---
title: "Replication Notes and Output for 'What Politicians Don't Know Can Hurt You: The effects of information on politicians’ spending decisions' American Political Science Review"
author: "Ryan Jablonski"
date: "6 July 2023"
output:
  pdf_document:
    toc: yes
    keep_tex: true
header-includes: \usepackage{float, makecell, longtable, rotating, lscape, hyperref} 
editor_options:
  chunk_output_type: console
---


\section{Replication Notes}

The code in this folder generates all the tables and figures from Ryan Jablonski and Brigitte Seim "What Politicians Don't Know Can Hurt You: The effects of information on politicians’ spending decisions" in the \textit{American Political Science Review}. The full output of the replication code is appended to this file.

This code is designed to be compiled with rMarkdown. It was originally run on RStudio Version RStudio 2022.07.1+554 with R 4.2.0 for Windows 10 x64. All data has been anonymized to protect respondents. 

The main replication file is GenerateTablesFigures.rmd. In order to replicate the results, you must first change the "working_dir" variable in this file to the directory of the replication files. 

Note that the results markdown file will differ in size and resolution from the main text. For final source files see the ./Output folder.


This replication code relies on the following source files:
		\begin{enumerate}
			\item{\emph{GenerateTablesFigures.rmd} This file is an rMarkdown file to generate all tables and figures}
			\item{\emph{./data/labels.csv} this file contains labels for all variables}
			\item{\emph{./data/all\_withcovariates.csv} this is a school-level dataset containing all variables used for the main treatment analysis}
			\item{\emph{./data/c\_withcovariates.csv} this is a school-level dataset containing all variables used for the councillor only treatment analysis}
			\item{\emph{./data/c\_withcovariates\_withattritted.csv} this is identical to the file above, but also includes attritted respondents. It is used for attrition analysis in the SI.}
			\item{\emph{./data/mp\_withcovariates.csv} this is a school-level dataset containing all variables used for the MP only treatment analysis}
					\item{\emph{./data/mp\_withcovariates\_withattritted.csv} this is identical to the file above, but also includes attritted respondents. It is used for attrition analysis in the SI.}
			\item{\emph{./data/citizen\_survey.csv} this file contains survey responses from citizens in the catchment area of a sample of schools included in this experiment. Among other things, it contains spatial data on patterns of politician visits to constituents.}
			\item{\emph{./data/citizen\_survey.csv} this file contains survey responses from citizens in the catchment area of a sample of schools included in this experiment. Among other things, it contains spatial data on patterns of politician visits to constituents.}
			\item{\emph{./data/headteacher\_survey.csv} this file contains survey responses from head teachers in the catchment area of a sample of schools included in this experiment. Among other things, it contains responses to a question about teacher prioritization of school needs.}
			\item{\emph{./data/how\_useful\_survey\_questions.csv} this file summarizes politician responses to an open ended question about the usefulness of information in the experiment.}
			\item{\emph{./data/followupsurvey.csv} this file contains politician responses to a follow-up phone survey about constituent information. It is used to generate Figure 1.}
						\item{\emph{./data/lc\_schools\_all.csv} this file contains details of schools which were eligible to be included in the experimental sample for councillors. It is used to generate sample summary data.}
						\item{\emph{./data/mp\_schools\_all.csv} this file contains details of schools which were eligible to be included in the experimental sample for MPs. It is used to generate sample summary data.}
								\item{\emph{./data/power\_sim.csv} this file contains power simulations for the main treatment effect.}
								\item{\emph{./data/power\_sim\_interactions.csv} this file contains power simulations for interactions between treatments.}
			
		\end{enumerate}
For questions about this replication contact Ryan Jablonski at r.s.jablonski@lse.ac.uk.




```{r setup, include=FALSE, echo=FALSE}

rm(list=ls(all=TRUE))
set.seed(81654)
working_dir=".\\APSR Replication\\"
knitr::opts_knit$set(root.dir = working_dir)
setwd(working_dir)


#using groundhog to ensure forward compatibility. This forces the code to rely on the same package versions as in the original analysis.
library(groundhog)
library(units)
groundhog.library(stargazer,'2023-04-01')
groundhog.library(gridExtra,'2023-04-01')
groundhog.library(stringr,'2023-04-01')
groundhog.library(ddpcr,'2023-04-01')
groundhog.library(ggplot2,'2023-04-01')
groundhog.library(survival,'2023-04-01')
groundhog.library(lfe,'2023-04-01') 
groundhog.library(lme4,'2023-04-01')
groundhog.library(foreign,'2023-04-01')
groundhog.library(broom,'2023-04-01')
groundhog.library(dotwhisker,'2023-04-01')
groundhog.library(dplyr,'2023-04-01')
groundhog.library(MASS,'2023-04-01')
groundhog.library(wesanderson,'2023-04-01')
groundhog.library(corrplot,'2023-04-01')
groundhog.library(dplyr,'2023-04-01')
groundhog.library(xtable,'2023-04-01')
groundhog.library(wesanderson,'2023-04-01')
groundhog.library(lavaan,'2023-04-01')
groundhog.library(geosphere,'2023-04-01')
groundhog.library(psych,'2023-04-01')
groundhog.library(plyr,'2023-04-01')
groundhog.library(forcats,'2023-04-01')
groundhog.library(lmtest,'2023-04-01')
groundhog.library(patchwork,'2023-04-01')
groundhog.library(expss,'2023-04-01')
 
library(tidyverse)

#this is the link to the dataverse file containing additional tables not shown in the SI
dataverse_markdown_url="https://doi.org/10.7910/DVN/HS5R5S"


mp.survey=read.csv("./data/mp_withcovariates.csv", stringsAsFactors = FALSE)
c.survey=read.csv("./data/c_withcovariates.csv", stringsAsFactors = FALSE)
all.surveys=read.csv("./data/all_withcovariates.csv", stringsAsFactors = FALSE)

mp.survey.all=read.csv("./data/mp_withcovariates_withattritted.csv", stringsAsFactors = FALSE)
c.survey.all=read.csv("./data/c_withcovariates_withattritted.csv", stringsAsFactors = FALSE)

schools.mp=read.csv("./data/mp_schools_all.csv")
schools.lc=read.csv("./data/lc_schools_all.csv")
citizen_survey=read.csv("./data/citizen_survey.csv")
headteacher_survey=read.csv("./data/headteacher_survey.csv")
followupsurvey=read.csv("./data/followupsurvey.csv")

#check if output folder exists
if(!dir.exists("Output")){
 dir.create("Output")
}


all.surveys.fullsample=all.surveys
c.survey.fullsample=c.survey
mp.survey.fullsample=mp.survey

#We exclude cases where politicians contested the boundaries of maps (since politicians never select schools they
#believe to be outside their constituency)
all.surveys=all.surveys[all.surveys$mapwithwrongschool==0,]
#all.surveys.old=all.surveys.old[all.surveys.old$mapwithwrongschool==0,]


c.survey=c.survey[c.survey$mapwithwrongschool==0,]
mp.survey=mp.survey[mp.survey$mapwithwrongschool==0,]

#a file containing labels for our variables (as well as an indicator of which are controls)
labels=read.csv("./data/labels.csv",stringsAsFactors=FALSE)

labels=subset(labels, !is.na(varname))
labels.all=labels
labels=labels[labels$include==1,]
labels = labels[order(labels$label),]
labels=labels[labels$alt.specific==1,]

#Create a vector of control variables for analysis
controls = ""
for(i in c(1:nrow(labels))){
  controls = paste(controls, labels$varname[i], sep=" + ")
}

controls.labels = ""
for(i in c(1:nrow(labels))){
  if(i==1){
      controls.labels = labels$label[i]
  } else {
    controls.labels = c(controls.labels, labels$label[i])
  }
}

controls.interactions=paste(controls, "information_votes*z_number_aid_categories", "information_need*z_number_aid_categories", "information_votes*z_past_aid_project", "information_need*z_past_aid_project", sep=" + ")


#a function to return the name of variables
labelme=function(varname, wrap=F, wrap_width=80){
  varname=str_remove_all(varname, "z_")
  this.label=""
  if(!grepl(":",varname)){
    this.label=labels.all[labels.all$varname==varname,]$label
  } else {
    varnames=strsplit(varname, ":")[[1]]
    this.label=labels.all[labels.all$varname==varnames[1],]$label
    for(i in 2:length(varnames)){
      this.label=paste(this.label, labels.all[labels.all$varname==varnames[i],]$label, sep="*")
    }
  }
  if(wrap==T){
    this.label=str_wrap(this.label, width = wrap_width, indent = 0, exdent = 0)
  }
  
  return(this.label)
}
  

#used for plotting multiple plots on one figure
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
  library(grid)
  
  # Make a list from the ... arguments and plotlist
  plots <- c(list(...), plotlist)
  
  numPlots = length(plots)
  
  # If layout is NULL, then use 'cols' to determine layout
  if (is.null(layout)) {
    # Make the panel
    # ncol: Number of columns of plots
    # nrow: Number of rows needed, calculated from # of cols
    layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
                     ncol = cols, nrow = ceiling(numPlots/cols))
  }
  
  if (numPlots==1) {
    print(plots[[1]])
    
  } else {
    # Set up the page
    grid.newpage()
    pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
    
    # Make each plot, in the correct location
    for (i in 1:numPlots) {
      # Get the i,j matrix positions of the regions that contain this subplot
      matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
      
      print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
                                      layout.pos.col = matchidx$col))
    }
  }
}

#a function to cleanup and print stargazer output
stargazer_print<-function(stargazer_text="", note="", filename="output.tex", supress_output=F, relabelr2=T){
  note.latex <- note
  stargazer_text[grepl("replace me",stargazer_text)] <- note.latex
  if(relabelr2==T){
   stargazer_text =str_replace(stargazer_text, "R\\$", "Pseudo-R$")
  }
  fileConn<-file(paste0("./Output/", filename))
  writeLines(stargazer_text, fileConn)
  close(fileConn) 
  if(supress_output==F){cat (stargazer_text, sep = "\n")}
}


```


\section{Effects of the Need Information Treatment}


\subsection{Conditional Logit Estimates of the Need Information Treatment (Figure 8, Table S8-S9, Figure S15, Table S35, Table 2)}

```{r information_need, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, ate_se=NA, pr=NA, pr.low=NA, pr.high=NA)

i=0
model_id=0

this.controls=gsub(" \\+  school_need_index","", controls)
this.controls.labels=controls.labels[controls.labels != "School Need Index"]


m1.c = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
m1.mp = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m1.pooled = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.pooled.controls = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index", this.controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
#all.surveys$ps_opposition_percent_mp

models <- list(m1.pooled, m1.pooled.controls, m1.c, m1.mp)
names <- c(labelme("school_need_index"), 
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n with Controls"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n only Councillors"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n only MPs")
           )

#loop through models and calculate marginal effects for plotting
for(m in models){
  
  this.var="school_need_index"
  this.treat="information_need"
  
  i=nrow(results)+1
  model_id=model_id+1
    
  t=1
  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$pr = exp(results[i,]$estimate)/(1+exp(results[i,]$estimate))
  results[i,]$pr.low = (results[i,]$conf.low)/(1+(results[i,]$conf.low))
  results[i,]$pr.high = (results[i,]$conf.high)/(1+(results[i,]$conf.high))

  t=0
  results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$pr = exp(results[i+1,]$estimate)/(1+exp(results[i+1,]$estimate))
  results[i+1,]$pr.low = (results[i+1,]$conf.low)/(1+(results[i+1,]$conf.low))
  results[i+1,]$pr.high = (results[i+1,]$conf.high)/(1+(results[i+1,]$conf.high))

}

all.surveys$trans_temp=all.surveys$transparency_all
m1.pooled.transparency = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*trans_temp + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
all.surveys$trans_temp=all.surveys$transparency_donor
m1.pooled.transparencydonor = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*trans_temp + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
all.surveys$trans_temp=all.surveys$transparency_radio
m1.pooled.transparencyradio = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*trans_temp + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)



models <- list(m1.pooled.transparency, m1.pooled.transparencydonor, m1.pooled.transparencyradio)
names <- c(paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Transparency Condition"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Donor Transparency"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Radio Transparency")
           )

#loop through models and calculate marginal effects for plotting
model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="school_need_index"
  this.treat="information_need"
  this.mediator="trans_temp"
  
  t=1
  k=1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$pr = exp(results[i,]$estimate)/(1+exp(results[i,]$estimate))
  results[i,]$pr.low = (results[i,]$conf.low)/(1+(results[i,]$conf.low))
  results[i,]$pr.high = (results[i,]$conf.high)/(1+(results[i,]$conf.high))

  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$pr = exp(results[i+1,]$estimate)/(1+exp(results[i+1,]$estimate))
  results[i+1,]$pr.low = (results[i+1,]$conf.low)/(1+(results[i+1,]$conf.low))
  results[i+1,]$pr.high = (results[i+1,]$conf.high)/(1+(results[i+1,]$conf.high))
  
    results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}


m1.pooled.knowledge = clogit(as.formula(paste("incumbentselected ~ information_need*school_knowledge*school_need_index+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.pooled.knowledge.controls = clogit(as.formula(paste("incumbentselected ~ information_need*school_knowledge*school_need_index", this.controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

models <- list(m1.pooled.knowledge, m1.pooled.knowledge)
names <- c(paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n High Knowledge"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Low Knowledge")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="school_need_index"
  this.treat="information_need"
  this.mediator="school_knowledge"

  t=1
  
  if(model_id==1){ k=0}
  if(model_id==2){ k=1}

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.mediator, ":", this.var), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.mediator, ":",this.var )]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.mediator, ":", this.var)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k^2*vcov(m)[paste0(this.mediator, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  
  t=0
    results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
    
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.mediator, ":", this.var), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.mediator, ":", this.var)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k^2*vcov(m)[paste0(this.mediator, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]
      )
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

      
}



results$exp_estimate = exp(results$estimate)
results=results[!is.na(results$model),]

results=results[order(results$model, results$model),]
results=results[!is.na(results$estimate),]

results$estimate=exp(results$estimate)


results.need=results[results$term %in% c("School Need Index", "School Need Index \n with Controls", "School Need Index \n Transparency Condition"),]


p=dwplot(results.need, 
         dot_args = list(aes(shape = as.character(results.need$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.need[results.need$model=="Treatment",])), x = rep(0.82, nrow(results.need[results.need$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.need[results.need$model=="Treatment",]$p.value,4),2))), size=3)+
  theme_bw() + xlab("Marginal Effect \n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.68, 0.031),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.1, r=0.1, t=0.1,b=0.1, unit='cm'),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(0.80, 1.5))+
  scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
  guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend


pdf("./Output/need_treatment_plot.pdf",width=5,height=3, family="Helvetica")
p
dev.off()
p
cat(paste("\n", sep=""))



results.need=results[results$term %in% c("School Need Index \n High Knowledge", "School Need Index \n Low Knowledge"),]

p=dwplot(results.need, 
         dot_args = list(aes(shape = as.character(results.need$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.need[results.need$model=="Treatment",])), x = rep(0.82, nrow(results.need[results.need$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.need[results.need$model=="Treatment",]$p.value,4),2))), size=3)+
  theme_bw() + xlab("Marginal Effect \n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.68, 0.031),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.1, r=0.1, t=0.1,b=0.1, unit='cm'),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(0.80, 1.5))+
  scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
  guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend


pdf("./Output/need_treatment_plot_knowledge.pdf",width=5,height=3, family="Helvetica")
p
dev.off()
p
cat(paste("\n", sep=""))

sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, type = "latex", 
          column.labels = NULL,
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          
          dep.var.caption  = "",
          title="The Effect of School Need Information on School Selection",
          order=c("^information_need:school_need_index$", "^school_need_index$"),
          keep=c("^information_need:school_need_index$", "^school_need_index$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_need",]$label, labels.all[labels.all$varname=="school_need_index",]$label, sep="*\n"), labels.all[labels.all$varname=="school_need_index",]$label),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_need", sep=""),
          table.placement = "H",
           add.lines=list(c("Controls", "No", "Yes"),
                    c("N Maps", summary(m1.pooled)$nevent, summary(m1.pooled.controls)$nevent), 
                          c("N Schools", summary(m1.pooled)$n, summary(m1.pooled.controls)$n))
          
))

stargazer_print(sg, "\\multicolumn{3}{p{0.9\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. See SI 3.3, Table S8 for complete model results.}", "tab_information_need.tex")



#with controls for SI
sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, m1.c, m1.mp, type = "latex", 
          out=paste("./Output/tab_information_need_expanded1.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 8 (part 1)",
          order=c("^information_need:school_need_index$", "^school_need_index$", "information_need", this.controls),
          keep="*",
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_need",]$label, labels.all[labels.all$varname=="school_need_index",]$label, sep="*\n"), labels.all[labels.all$varname=="school_need_index",]$label,
                               labels.all[labels.all$varname=="information_need",]$label, this.controls.labels),
          no.space=TRUE,
          label=paste("tab_information_need_expanded1", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_need_expanded1.tex")



sg=capture.output(stargazer(m1.pooled.transparency, type = "latex", 
          out=paste("./Output/tab_information_need_expanded2.tex", sep=""), 
          column.labels = c("Transparency Interactions"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 8 (part 2)",
          order=c("^information_need:school_need_index:trans_temp$", 
                  "^information_need:school_need_index$",
                  "^school_need_index:trans_temp$", 
                  "^information_need:trans_temp$", 
                  "^school_need_index$", 
                  "information_need"),
          keep="*",
          covariate.labels = c(labelme("information_need:school_need_index:transparency_all"),
                               labelme("information_need:school_need_index"),
                               labelme("school_need_index:transparency_all"),
                               labelme("information_need:transparency_all"),
                               labelme("school_need_index"), 
                               labelme("information_need"), 
                               labelme("transparency_all")),
          no.space=TRUE,
          label=paste("tab_information_need_expanded2", sep=""),
          table.placement = "H"
          
))


stargazer_print(sg, "\\multicolumn{2}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_need_expanded2.tex")



sg=capture.output(stargazer(m1.pooled.knowledge,m1.pooled.knowledge.controls, type = "latex", 
          out=NULL,
          column.labels = c("without controls","with controls"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interactions of Need Information Treatment with School Knowledge",
          order=c("^information_need:school_knowledge:school_need_index$",
                  "^information_need:school_need_index$",
                  "^school_knowledge:school_need_index$",
                  "^information_need:school_knowledge$", 
                  "^school_need_index$", 
                  "information_need", 
                  "school_knowledge"),
          keep=c("^information_need:school_knowledge:school_need_index$",
                  "^information_need:school_need_index$",
                  "^school_knowledge:school_need_index$",
                  "^information_need:school_knowledge$", 
                  "^school_need_index$", 
                  "information_need", 
                  "school_knowledge"),
          covariate.labels = c(labelme("information_need:school_knowledge:school_need_index"),
                               labelme("information_need:school_need_index"),
                               labelme("school_knowledge:school_need_index"),
                               labelme("information_need:school_knowledge"), 
                               labelme("school_need_index"), 
                               labelme("information_need"), 
                               labelme("school_knowledge")),
          no.space=TRUE,
          label=paste("tab_information_need_knowledge", sep=""),
          table.placement = "H"
          
))



stargazer_print(sg, paste0("\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_information_need_knowledge_full}).}"), "tab_information_need_knowledge.tex", supress_output=F)


sg=capture.output(stargazer(m1.pooled.knowledge,m1.pooled.knowledge.controls, type = "latex", 
          out=NULL,
          column.labels = c("without controls","with controls"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interactions of Need Information Treatment with School Knowledge, Full Model",
          order=c("^information_need:school_knowledge:school_need_index$",
                  "^information_need:school_need_index$",
                  "^school_knowledge:school_need_index$",
                  "^information_need:school_knowledge$", 
                  "^school_need_index$", 
                  "information_need", 
                  "school_knowledge"),
          covariate.labels = c(labelme("information_need:school_knowledge:school_need_index"),
                               labelme("information_need:school_need_index"),
                               labelme("school_knowledge:school_need_index"),
                               labelme("information_need:school_knowledge"), 
                               labelme("school_need_index"), 
                               labelme("information_need"), 
                               labelme("school_knowledge")),
          no.space=TRUE,
          label=paste("tab_information_need_knowledge_full", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_need_knowledge_full.tex")



```

\subsection{Linear Probability Model Estimates of the Need Information Treatment (Figure S8)}

```{r information_need_lm, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, ate_se=NA)

i=0
model_id=0

this.controls=gsub(" \\+  school_need_index","", controls)
this.controls.labels=controls.labels[controls.labels != "School Need Index"]
m1.c = felm(as.formula(paste("incumbentselected ~ information_need*school_need_index | map_id |0|resp_id")),  c.survey)  
m1.mp = felm(as.formula(paste("incumbentselected ~ information_need*school_need_index | map_id |0|resp_id")),  mp.survey)
m1.pooled = felm(as.formula(paste("incumbentselected ~ information_need*school_need_index | map_id |0|resp_id")),  all.surveys)
m1.pooled.controls = felm(as.formula(paste("incumbentselected ~ information_need*school_need_index",this.controls," | map_id |0|resp_id")), all.surveys)  


models <- list(m1.pooled, m1.pooled.controls, m1.c, m1.mp)
names <- c(labelme("school_need_index"), 
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n with Controls"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n only Councillors"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n only MPs")
           )



for(m in models){
  this.var="school_need_index"
  this.treat="information_need"
  
  i=nrow(results)+1
  model_id=model_id+1
    
  t=1
  
  results[i,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "Cluster s.e."]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|t|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=(results[i,]$estimate-qt(0.975,df=m$N-1)*results[i,]$robust.se)
  results[i,]$conf.high=(results[i,]$estimate +qt(0.975,df=m$N-1)*results[i,]$robust.se)
  
  t=0
  results[i+1,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "Cluster s.e."]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|t|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=(results[i+1,]$estimate-qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=(results[i+1,]$estimate +qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
}


all.surveys$trans_temp=all.surveys$transparency_all
m1.pooled.transparency = felm(as.formula(paste("incumbentselected ~ information_need*school_need_index*trans_temp  | map_id |0|resp_id")),  all.surveys)
all.surveys$trans_temp=all.surveys$transparency_donor
m1.pooled.transparencydonor = felm(as.formula(paste("incumbentselected ~ information_need*school_need_index*trans_temp | map_id |0|resp_id")),  all.surveys)
all.surveys$trans_temp=all.surveys$transparency_radio
m1.pooled.transparencyradio = felm(as.formula(paste("incumbentselected ~ information_need*school_need_index*trans_temp | map_id |0|resp_id")),  all.surveys)



models <- list(m1.pooled.transparency, m1.pooled.transparencydonor, m1.pooled.transparencyradio)
names <- c(paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Transparency Condition"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Donor Transparency"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Radio Transparency")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="school_need_index"
  this.treat="information_need"
  this.mediator="trans_temp"
  
  t=1
  k=1

  
  results[i,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator),]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator),]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var),]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator),]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "Cluster s.e."]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "Cluster s.e."]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "Cluster s.e."]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "Cluster s.e."]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=(results[i,]$estimate-qt(0.975,df=m$N-1)*results[i,]$robust.se)
  results[i,]$conf.high=(results[i,]$estimate +qt(0.975,df=m$N-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator),]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator),]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "Cluster s.e."]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "Cluster s.e."]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "Cluster s.e."]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=(results[i+1,]$estimate-qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=(results[i+1,]$estimate +qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$N-1, lower=FALSE)

}



results=results[!is.na(results$model),]
results=results[order(results$model, results$model),]
results=results[!is.na(results$estimate),]

results.need=results

results.need=results.need[results.need$term %in% c("School Need Index", "School Need Index \n with Controls", "School Need Index \n Transparency Condition"),]



p=dwplot(results.need, 
         dot_args = list(aes(shape = as.character(results.need$model))),
       vline = geom_vline(xintercept = 0, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.need[results.need$model=="Treatment",])), x = rep(-0.13, nrow(results.need[results.need$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.need[results.need$model=="Treatment",]$p.value,4),2))), size=3)+
  theme_bw() + xlab("Marginal Effect \n(Linear Probability Model)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.72, 0.031),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.1, r=0.1, t=0.1,b=0.1, unit='cm'),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(-0.15, 0.18))+
  scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
  guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend


pdf("./Output/need_treatment_plot_lpm.pdf",width=5,height=4, family="Helvetica")
p
dev.off()

p
cat(paste("\n", sep=""))



sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, type = "latex", 
          out=paste("./Output/tab_information_need_lpm.tex", sep=""), 
          column.labels = c("All Surveys","with Controls"),
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of School Need Information, Linear Estimates",
          order=c("^information_need:school_need_index$", "^school_need_index$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_need",]$label, labels.all[labels.all$varname=="school_need_index",]$label, sep="*\n"), labels.all[labels.all$varname=="school_need_index",]$label),
          no.space=TRUE,
          label=paste("tab_information_need_lpm", sep=""),
          table.placement = "H")
          
)


stargazer_print(sg, "\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients from linear fixed effect regressions on school selection. Standard errors are clustered on politician.}", "tab_information_need_lpm.tex", relabelr2=F)


#with controls for dataverse

sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, m1.c, m1.mp, type = "latex", 
          out=paste("./Output/tab_information_need_expanded1_lpm.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of School Need Information, Linear Estimates",
          order=c("^information_need:school_need_index$", "^school_need_index$", "information_need", this.controls),
          keep="*",
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_need",]$label, labels.all[labels.all$varname=="school_need_index",]$label, sep="*\n"), labels.all[labels.all$varname=="school_need_index",]$label,
                               labels.all[labels.all$varname=="information_need",]$label, this.controls.labels),
          no.space=TRUE,
          label=paste("tab_information_need_expanded1_lpm", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients from linear fixed effect regressions on school selection. Standard errors are clustered on politician.}", "tab_information_need_lpm.tex", relabelr2=F)


sg=capture.output(stargazer(m1.pooled.transparency, type = "latex", 
          out=paste("./Output/tab_information_need_expanded2_lpm.tex", sep=""), 
          column.labels = c("Transparency Interactions"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interactions of Need Information with Transparency, Linear Estimates",
          order=c("^information_need:school_need_index:trans_temp$", 
                  "^information_need:school_need_index$",
                  "^school_need_index:trans_temp$", 
                  "^information_need:trans_temp$", 
                  "^school_need_index$", 
                  "information_need"),
          keep="*",
          covariate.labels = c(labelme("information_need:school_need_index:transparency_all"),
                               labelme("information_need:school_need_index"),
                               labelme("school_need_index:transparency_all"),
                               labelme("information_need:transparency_all"),
                               labelme("school_need_index"), 
                               labelme("information_need"), 
                               labelme("transparency_all")),
          no.space=TRUE,
          label=paste("tab_information_need_expanded2_lpm", sep=""),
          table.placement = "H"
          
))


stargazer_print(sg, "\\multicolumn{2}{p{\\textwidth}}{This table shows the coefficients from linear fixed effect regressions on school selection. Standard errors are clustered on politician.}", "tab_information_need_lpm.tex", relabelr2=F)




```

\subsection{Heterogenous Effects of the Need Information Treatment (Figure S4)}

```{r information_need_het, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, ate_se=NA)

i=0
model_id=0


all.surveys$genderM=ifelse(all.surveys$gender=="Male", 1, 0)
m1.gender = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*genderM + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

models <- list(m1.gender, m1.gender)
names <- c(paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Male Politicians"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Female Politicians")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="school_need_index"
  this.treat="information_need"
  this.mediator="genderM"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}


all.surveys$timeliving=NA
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("Donâ<U+0080><U+0099>t know", "Decline to answer"), NA, all.surveys$timeliving)
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("Less than 5 years", "5 to 10 years"), 0, all.surveys$timeliving)
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("More than 10 years"), 1, all.surveys$timeliving)
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("All of my life"), 1, all.surveys$timeliving)


m1.timeliving = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*timeliving + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.timeliving, m1.timeliving)
names <- c(paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Lived in constituency < 10 years"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Lived in constituency > 10 years")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="school_need_index"
  this.treat="information_need"
  this.mediator="timeliving"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}



m1.contest = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*contest_electionYes + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.contest, m1.contest)
names <- c(paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Contesting election=Yes"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Contesting election=No or Unsure")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="school_need_index"
  this.treat="information_need"
  this.mediator="contest_electionYes"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
    results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}


m1.useful = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*useful + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.useful, m1.useful, m1.useful)
names <- c(paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Information=Not very useful"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Information=Somewhat useful"),
           paste(labels.all[labels.all$varname=="school_need_index",]$label, "\n Information=Very useful")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="school_need_index"
  this.treat="information_need"
  this.mediator="useful"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
    results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}


results$exp_estimate = exp(results$estimate)
results=results[!is.na(results$model),]
results=results[order(results$model, results$model),]
results=results[!is.na(results$estimate),]
results$estimate=results$exp_estimate

results.need=results


p=dwplot(results.need, 
         dot_args = list(aes(shape = as.character(results.need$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.need[results.need$model=="Treatment",])), x = rep(0.52, nrow(results.need[results.need$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.need[results.need$model=="Treatment",]$p.value,4),2))), size=3)+
  theme_bw() + xlab("Marginal Effect \n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.70, 0.031),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.1, r=0.1, t=0.1,b=0.1, unit='cm'),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(0.50, 1.7))+
  scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
  guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend

pdf("./Output/need_treatment_plot_het.pdf",width=5.6,height=4, family="Helvetica")
p
dev.off()
p
cat(paste("\n", sep=""))


sg=capture.output(stargazer(m1.contest, m1.gender, m1.timeliving, m1.useful, type = "latex", 
          out=NULL, 
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Need Information, Heterogenous Effects",
          no.space=TRUE,
          label=paste("tab_need_treatment_plot_het", sep=""),
          table.placement = "H")
          
)

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_need_treatment_plot_het.tex")



```


\subsection{Additional Pre-Registered Tests of the Need Information Treatment (Figure S7)}
```{r information_need_supp, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, ate_se=NA)

i=0
model_id=0

m1 = clogit(as.formula(paste("incumbentselected ~ information_need*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

controls1=gsub("winner_percent_imp \\+ ", "", controls)
m1.controls = clogit(as.formula(paste("incumbentselected ~ information_need*z_winner_percent", controls1, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)  


m2 = clogit(as.formula(paste("incumbentselected ~ information_need*any_children_attend_school + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m2.controls = clogit(as.formula(paste("incumbentselected ~ information_need*any_children_attend_school", controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)  

m3 = clogit(as.formula(paste("incumbentselected ~ information_need*z_school_home_distance + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m3.controls = clogit(as.formula(paste("incumbentselected ~ information_need*z_school_home_distance", controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)  


models <- list(m1, m1.controls)

names <- c(paste(labels.all[labels.all$varname=="winner_percent",]$label),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n with Controls")
           )


for(m in models){
  
  this.var="z_winner_percent"
  this.treat="information_need"
  
  i=nrow(results)+1
  model_id=model_id+1
    
  t=1
  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
  results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)

}


models <- list(m2, m2.controls)
names <- c(paste(labels.all[labels.all$varname=="any_children_attend_school",]$label),
           paste(labels.all[labels.all$varname=="any_children_attend_school",]$label, "\n with Controls")
           )

model_id=0
for(m in models){
  
  this.var="any_children_attend_school"
  this.treat="information_need"
  
  i=nrow(results)+1
  model_id=model_id+1
    
  t=1
  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
  results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
}

models <- list(m3, m3.controls)
names <- c(paste(labels.all[labels.all$varname=="school_home_distance",]$label),
           paste(labels.all[labels.all$varname=="school_home_distance",]$label, "\n with Controls")
           )

model_id=0
for(m in models){
  
  this.var="z_school_home_distance"
  this.treat="information_need"
  
  i=nrow(results)+1
  model_id=model_id+1
    
  t=1
  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
  results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
}


results$estimate=exp(results$estimate)

results=results[-1,]
results.need=results


p=dwplot(results.need, 
        dot_args = list(aes(shape = as.character(results.need$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.need[results.need$model=="Treatment",])), x = rep(0.3, nrow(results.need[results.need$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.need[results.need$model=="Treatment",]$p.value,4),2))), size=3)+
  theme_bw() + xlab("Marginal Effect \n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.70, 0.01),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.1, r=0.1, t=0.1,b=0.1, unit='cm'),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(0.3, 2.1))+
    scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
    guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend

pdf("./Output/need_treatment_plot_supplementary.pdf",width=6,height=4.0, family="Helvetica")
p
dev.off()
p
cat(paste("\n", sep=""))


sg=capture.output(stargazer(m1, m1.controls, m2, m2.controls, m3, m3.controls, type = "latex", 
          out=paste("./Output/tab_need_treatment_plot_supplementary.tex", sep=""), 
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Additional Pre-Registered Tests of the Need Information Treatment",
          no.space=TRUE,
          label=paste("tab_need_treatment_plot_supplementary", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{7}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_need_treatment_plot_supplementary.tex")



```

\section{Effects of the Voting Information Treatment}


\subsection{Conditional Logit Estimates of the Voting Information Treatment (Figure 10, Table S12-S13, Figure S17, Table S37, Table 4)}
```{r information_votes_clogit, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

#remove winner percent from controls
this.controls=gsub(" \\+ winner_percent_imp","", controls)
this.controls.labels=controls.labels[controls.labels != "Incumbent Percent"]


results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, ate_se=NA)

i=0
model_id=0

m1.c = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)  
m1.mp = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m1.pooled = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.pooled.controls = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent", this.controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)  

models <- list(m1.pooled, m1.pooled.controls, m1.mp, m1.c)
names <- c(labelme("winner_percent"), 
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n with Controls"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n only MPs"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n only Councillors")
           )


for(m in models){
  
  this.var="z_winner_percent"
  this.treat="information_votes"
  
  i=nrow(results)+1
  model_id=model_id+1
    
  t=1
  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
  results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
}


all.surveys$trans_temp=all.surveys$transparency_all
m1.pooled.transparency = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*trans_temp + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
all.surveys$trans_temp=all.surveys$transparency_donor
m1.pooled.transparencydonor = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*trans_temp + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
all.surveys$trans_temp=all.surveys$transparency_radio
m1.pooled.transparencyradio = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*trans_temp + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.pooled.transparency, m1.pooled.transparencydonor, m1.pooled.transparencyradio)
names <- c(paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Transparency Condition"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Donor Transparency"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Radio Transparency")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_winner_percent"
  this.treat="information_votes"
  this.mediator="trans_temp"
  
  t=1
  k=1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
     results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

      
}


m1.pooled.knowledge = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*political_knowledge + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m1.pooled.knowledge.controls = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*political_knowledge",this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

models <- list(m1.pooled.knowledge, m1.pooled.knowledge)
names <- c(paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n High Knowledge"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Low Knowledge")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_winner_percent"
  this.treat="information_votes"
  this.mediator="political_knowledge"
  
  t=1
if(model_id==1){ k=0}
  if(model_id==2){ k=1}

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
     results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

      
}




results$estimate = exp(results$estimate)
results=results[!is.na(results$model),]

results=results[order(results$model, results$model),]
results=results[!is.na(results$estimate),]
           


results.votes=results[results$term %in% c("Incumbent Percent", "Incumbent Percent \n Transparency Condition", "Incumbent Percent \n with Controls"),]

p=dwplot(results.votes, 
                  dot_args = list(aes(shape = as.character(results.votes$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.votes[results.votes$model=="Treatment",])), x = rep(0.62, nrow(results.votes[results.votes$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.votes[results.votes$model=="Treatment",]$p.value,3),2))), size=3)+
  theme_bw() + xlab("Marginal Effect\n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.68, 0.03),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.03, r=0.1, t=0.1,b=0.1, unit='cm'),
        plot.margin = unit(c(0.1,0.4,0.1,0.1), "cm"),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(0.60, 1.75), clip="off")+
    scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
    guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend



pdf("./Output/voting_treatment_plot.pdf",width=5,height=3, family="Helvetica")
p
dev.off()
p
cat(paste("\n", sep=""))


results.votes=results[results$term %in% c("Incumbent Percent \n High Knowledge", "Incumbent Percent \n Low Knowledge"),]


p=dwplot(results.votes, 
                  dot_args = list(aes(shape = as.character(results.votes$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.votes[results.votes$model=="Treatment",])), x = rep(0.62, nrow(results.votes[results.votes$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.votes[results.votes$model=="Treatment",]$p.value,3),2))), size=3)+
  theme_bw() + xlab("Marginal Effect\n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.68, 0.03),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.03, r=0.1, t=0.1,b=0.1, unit='cm'),
        plot.margin = unit(c(0.1,0.4,0.1,0.1), "cm"),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(0.60, 1.75), clip="off")+
    scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
    guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend



pdf("./Output/voting_treatment_plot_knowledge.pdf",width=5,height=3, family="Helvetica")
p
dev.off()
p
cat(paste("\n", sep=""))


sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, type = "latex", 
          out=paste("./Output/tab_information_votes.tex", sep=""), 
          column.labels = NULL,          
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Political Information on School Selection",
          order=c("^information_votes:z_winner_percent$", "^z_winner_percent$"),
          keep=c("^information_votes:z_winner_percent$", "^z_winner_percent$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_votes",]$label, labels.all[labels.all$varname=="winner_percent",]$label, sep="*\n"), labels.all[labels.all$varname=="winner_percent",]$label),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_votes", sep=""),
          table.placement = "H",
          add.lines=list(c("Controls", "No", "Yes"),
            c("N Maps", summary(m1.pooled)$nevent, summary(m1.pooled.controls)$nevent), 
                          c("N Schools", summary(m1.pooled)$n, summary(m1.pooled.controls)$n))
          
))

stargazer_print(sg, "\\multicolumn{3}{p{0.9\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results are in SI 3.3, Table S12.}", "tab_information_votes.tex")



#with controls for SI

sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, m1.c, m1.mp, type = "latex", 
          out=paste("./Output/tab_information_votes_expanded1.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 10 (part 1)",
          order=c("^information_votes:z_winner_percent$", "^z_winner_percent$", "^information_votes$", this.controls),
          keep=c("*"),
          covariate.labels = c(labelme("information_votes:z_winner_percent"), labelme("winner_percent"), labelme("information_votes"), this.controls.labels),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_votes_expanded1", sep=""),
          table.placement = "H"
          
))


stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_votes_expanded1.tex")


sg=capture.output(stargazer(m1.pooled.transparency, type = "latex", 
          out=paste("./Output/tab_information_votes_expanded2.tex", sep=""), 
          column.labels = c("Transparency Interactions"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 10 (part 2)",
          order=c("^information_votes:z_winner_percent:trans_temp$", 
                  "^information_votes:z_winner_percent$",
                  "^z_winner_percent:trans_temp$", 
                  "^information_votes:trans_temp$", 
                  "^z_winner_percent$", 
                  "information_votes"),
          keep="*",
          covariate.labels = c(labelme("information_votes:z_winner_percent:transparency_all"),
                               labelme("information_votes:z_winner_percent"),
                               labelme("winner_percent:transparency_all"),
                               labelme("information_votes:transparency_all"),
                               labelme("winner_percent"), 
                               labelme("information_votes"), 
                               labelme("transparency_all")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_votes_expanded2", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{2}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_votes_expanded2.tex")





sg=capture.output(stargazer(m1.pooled.knowledge,m1.pooled.knowledge.controls, type = "latex", 
          out=paste("./Output/tab_information_votes_knowledge.tex", sep=""), 
          column.labels = c("without controls","with controls"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interactions of Voting Information Treatment with Voting Knowledge",
          order=c("^information_votes:z_winner_percent:political_knowledge$",
                  "^information_votes:z_winner_percent$",
                  "^z_winner_percent:political_knowledge$",
                  "^information_votes:political_knowledge$", 
                  "^z_winner_percent$", 
                  "information_votes", 
                  "political_knowledge"),
          keep=c("^information_votes:z_winner_percent:political_knowledge$",
                  "^information_votes:z_winner_percent$",
                  "^z_winner_percent:political_knowledge$",
                  "^information_votes:political_knowledge$", 
                  "^z_winner_percent$", 
                  "information_votes", 
                  "political_knowledge"),
          covariate.labels = c(labelme("information_votes:political_knowledge:z_winner_percent"),
                               labelme("information_votes:z_winner_percent"),
                               labelme("political_knowledge:z_winner_percent"),
                               labelme("information_votes:political_knowledge"), 
                               labelme("winner_percent"), 
                               labelme("information_votes"), 
                               labelme("political_knowledge")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_votes_knowledge", sep=""),
          table.placement = "H"
          
))



stargazer_print(sg, paste0("\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_information_votes_knowledge_full}).}"), "tab_information_votes_knowledge.tex", supress_output=F)




sg=capture.output(stargazer(m1.pooled.knowledge,m1.pooled.knowledge.controls, type = "latex", 
          out=NULL,
          column.labels = c("without controls","with controls"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interactions of Voting Information Treatment with Voting Knowledge",
          order=c("^information_votes:z_winner_percent:political_knowledge$",
                  "^information_votes:z_winner_percent$",
                  "^z_winner_percent:political_knowledge$",
                  "^information_votes:political_knowledge$", 
                  "^z_winner_percent$", 
                  "information_votes", 
                  "political_knowledge"),
          keep=c("^information_votes:z_winner_percent:political_knowledge$",
                  "^information_votes:z_winner_percent$",
                  "^z_winner_percent:political_knowledge$",
                  "^information_votes:political_knowledge$", 
                  "^z_winner_percent$", 
                  "information_votes", 
                  "political_knowledge"),
          covariate.labels = c(labelme("information_votes:political_knowledge:z_winner_percent"),
                               labelme("information_votes:z_winner_percent"),
                               labelme("political_knowledge:z_winner_percent"),
                               labelme("information_votes:political_knowledge"), 
                               labelme("winner_percent"), 
                               labelme("information_votes"), 
                               labelme("political_knowledge")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_votes_knowledge_full", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_votes_knowledge_full.tex")


```


\subsection{Linear Probability Model Estimates of the Voting Information Treatment (Figure S10)}
```{r information_votes_lpm, message=FALSE, warning=FALSE, results='asis', echo=FALSE, eval=T}

this.controls=gsub(" \\+ winner_percent_imp","", controls)
this.controls.labels=controls.labels[controls.labels != "Incumbent Percent"]


results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, ate_se=NA)

i=0
model_id=0


m1.c = felm(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent | map_id |0|resp_id")),  c.survey)  
m1.mp = felm(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent | map_id |0|resp_id")),  mp.survey)
m1.pooled = felm(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent | map_id |0|resp_id")),  all.surveys)
m1.pooled.controls = felm(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent", this.controls, "| map_id |0|resp_id")),  all.surveys)  



models <- list(m1.pooled, m1.pooled.controls, m1.mp, m1.c)
names <- c(labelme("winner_percent"), 
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n with Controls"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n only MPs"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n only Councillors")
           )


for(m in models){
  
  this.var="z_winner_percent"
  this.treat="information_votes"
  
  i=nrow(results)+1
  model_id=model_id+1
    t=1
    
  results[i,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "Cluster s.e."]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|t|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=(results[i,]$estimate-qt(0.975,df=m$N-1)*results[i,]$robust.se)
  results[i,]$conf.high=(results[i,]$estimate +qt(0.975,df=m$N-1)*results[i,]$robust.se)
  
  t=0
  results[i+1,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "Cluster s.e."]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|t|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=(results[i+1,]$estimate-qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=(results[i+1,]$estimate +qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
}


all.surveys$trans_temp=all.surveys$transparency_all
m1.pooled.transparency = felm(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*trans_temp | map_id |0|resp_id")),  all.surveys)
all.surveys$trans_temp=all.surveys$transparency_donor
m1.pooled.transparencydonor = felm(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*trans_temp | map_id |0|resp_id")),  all.surveys)
all.surveys$trans_temp=all.surveys$transparency_radio
m1.pooled.transparencyradio = felm(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*trans_temp | map_id |0|resp_id")),  all.surveys)


models <- list(m1.pooled.transparency, m1.pooled.transparencydonor, m1.pooled.transparencyradio)
names <- c(paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Transparency Condition"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Donor Transparency"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Radio Transparency")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_winner_percent"
  this.treat="information_votes"
  this.mediator="trans_temp"
  
  t=1
  k=1

  
  results[i,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator),]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator),]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var),]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator),]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "Cluster s.e."]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "Cluster s.e."]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "Cluster s.e."]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "Cluster s.e."]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=(results[i,]$estimate-qt(0.975,df=m$N-1)*results[i,]$robust.se)
  results[i,]$conf.high=(results[i,]$estimate +qt(0.975,df=m$N-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator),]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator),]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "Cluster s.e."]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "Cluster s.e."]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "Cluster s.e."]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=(results[i+1,]$estimate-qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=(results[i+1,]$estimate +qt(0.975,df=m$N-1)*results[i+1,]$robust.se)

    results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$N-1, lower=FALSE)

      
}


results=results[!is.na(results$model),]

results=results[order(results$model, results$model),]
results=results[!is.na(results$estimate),]
           

results.votes=results

results.votes=results.votes[results.votes$term %in% c("Incumbent Percent", "Incumbent Percent \n Transparency Condition", "Incumbent Percent \n with Controls"),]

p=dwplot(results.votes, 
                  dot_args = list(aes(shape = as.character(results.votes$model))),
       vline = geom_vline(xintercept = 0, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.votes[results.votes$model=="Treatment",])), x = rep(-0.23, nrow(results.votes[results.votes$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.votes[results.votes$model=="Treatment",]$p.value,3),2))), size=3)+
  theme_bw() + xlab("Marginal Effect\n(Linear Probability Model)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.72, 0.03),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.03, r=0.1, t=0.1,b=0.1, unit='cm'),
        plot.margin = unit(c(0.1,0.4,0.1,0.1), "cm"),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(-0.25, 0.28), clip="off")+
    scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
    guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend



pdf("./Output/voting_treatment_plot_lpm.pdf",width=5,height=4, family="Helvetica")
p
dev.off()
p
cat(paste("\n", sep=""))


sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, type = "latex", 
          out=paste("./Output/tab_information_votes_lpm.tex", sep=""), 
          column.labels = c("All Surveys","with Controls"),          
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Political Information, Linear Model",
          order=c("^information_votes:z_winner_percent$", "^z_winner_percent$"),
          keep=c("^information_votes:z_winner_percent$", "^z_winner_percent$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_votes",]$label, labels.all[labels.all$varname=="winner_percent",]$label, sep="*\n"), labels.all[labels.all$varname=="winner_percent",]$label),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_votes_lpm", sep=""),
          table.placement = "H",
          add.lines=list(c("N Maps",nlevels(m1.pooled$fe$map_id), nlevels(m1.pooled.controls$fe$map_id)), 
                          c("N Schools", summary(m1.pooled)$N, summary(m1.pooled.controls)$N))
))

stargazer_print(sg, "\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients linear fixed effect regressions on school selection. Standard errors are clustered on politician. }", "tab_information_votes_lpm.tex", relabelr2=F)



#with controls

sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, m1.c, m1.mp, type = "latex", 
          out=paste("./Output/tab_information_votes_expanded1_lpm.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Linear Probability Model Estimates of the Need Information Treatmen (Figure S9)",
          order=c("^information_votes:z_winner_percent$", "^z_winner_percent$", "^information_votes$", this.controls),
          keep=c("*"),
          covariate.labels = c(labelme("information_votes:z_winner_percent"), labelme("winner_percent"), labelme("information_votes"), this.controls.labels),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_votes_expanded1_lpm", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients linear fixed effect regressions on school selection. Standard errors are clustered on politician. }", "tab_information_votes_expanded1_lpm.tex", relabelr2=F)



sg=capture.output(stargazer(m1.pooled.transparency, type = "latex", 
          out=paste("./Output/tab_information_votes_expanded2_lpm.tex", sep=""), 
          column.labels = c("Transparency Interactions"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 9 (part 2), Linear Model",
          order=c("^information_votes:z_winner_percent:trans_temp$", 
                  "^information_votes:z_winner_percent$",
                  "^z_winner_percent:trans_temp$", 
                  "^information_votes:trans_temp$", 
                  "^z_winner_percent$", 
                  "information_votes"),
          keep="*",
          covariate.labels = c(labelme("information_votes:z_winner_percent:transparency_all"),
                               labelme("information_votes:z_winner_percent"),
                               labelme("winner_percent:transparency_all"),
                               labelme("information_votes:transparency_all"),
                               labelme("winner_percent"), 
                               labelme("information_votes"), 
                               labelme("transparency_all")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_votes_expanded2_lpm", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{2}{p{\\textwidth}}{This table shows the coefficients linear fixed effect regressions on school selection. Standard errors are clustered on politician. }", "tab_information_votes_expanded2_lpm.tex", relabelr2=F)


```

\subsection{Heterogenous Effects of the Voting Information Treatment (Figure S6)}

```{r information_votes_het, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, ate_se=NA)

i=0
model_id=0


all.surveys$genderM=ifelse(all.surveys$gender=="Male", 1, 0)
m1.gender = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*genderM + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

models <- list(m1.gender, m1.gender)
names <- c(paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Male Politicians"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Female Politicians")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_winner_percent"
  this.treat="information_votes"
  this.mediator="genderM"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}


all.surveys$timeliving=NA
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("Donâ<U+0080><U+0099>t know", "Decline to answer"), NA, all.surveys$timeliving)
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("Less than 5 years", "5 to 10 years"), 0, all.surveys$timeliving)
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("More than 10 years"), 1, all.surveys$timeliving)
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("All of my life"), 1, all.surveys$timeliving)


m1.timeliving = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*timeliving + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.timeliving, m1.timeliving)
names <- c(paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Lived in constituency < 10 years"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Lived in constituency > 10 years")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_winner_percent"
  this.treat="information_votes"
  this.mediator="timeliving"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}



m1.contest = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*contest_electionYes + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.contest, m1.contest)
names <- c(paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Contesting election=Yes"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Contesting election=No or Unsure")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_winner_percent"
  this.treat="information_votes"
  this.mediator="contest_electionYes"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
    results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}


m1.useful = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*useful + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.useful, m1.useful, m1.useful)
names <- c(paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Information=Not very useful"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Information=Somewhat useful"),
           paste(labels.all[labels.all$varname=="winner_percent",]$label, "\n Information=Very useful")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_winner_percent"
  this.treat="information_votes"
  this.mediator="useful"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}




results$exp_estimate = exp(results$estimate)
results=results[!is.na(results$model),]

results=results[order(results$model, results$model),]
results=results[!is.na(results$estimate),]

results$estimate=exp(results$estimate)

results.votes=results



p=dwplot(results.votes, 
         dot_args = list(aes(shape = as.character(results.votes$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.votes[results.votes$model=="Treatment",])), x = rep(0.32, nrow(results.votes[results.votes$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.votes[results.votes$model=="Treatment",]$p.value,4),2))), size=3)+
  theme_bw() + xlab("Marginal Effect \n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.65, 0.031),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.1, r=0.1, t=0.1,b=0.1, unit='cm'),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
coord_cartesian(xlim=c(0.30, 1.85))+
  scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
  guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend


pdf("./Output/votes_treatment_plot_het.pdf",width=5.6,height=4, family="Helvetica")
p
dev.off()
p
cat(paste("\n", sep=""))



sg=capture.output(stargazer(m1.contest, m1.gender, m1.timeliving, m1.useful, type = "latex", 
          out=NULL, 
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Voting Information, Heterogenous Effects",
          no.space=TRUE,
          label=paste("tab_votes_treatment_plot_het", sep=""),
          table.placement = "H")
          
)

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_votes_treatment_plot_het.tex")





```

\subsection{Estimates with Alternative Coding of Voting (Tables S29 and S30)}
```{r votes_non_linear, message=FALSE, warning=FALSE, results='asis', echo=FALSE, eval=T}

all.surveys$sq_winner_percent= all.surveys$winner_percent^2
c.survey$sq_winner_percent= c.survey$winner_percent^2
mp.survey$sq_winner_percent= mp.survey$winner_percent^2

this.controls=sub("winner_percent_imp \\+", "", controls)
h1.c = clogit(as.formula(paste("incumbentselected ~ winner_percent + sq_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_votes==0,])  
h1.mp = clogit(as.formula(paste("incumbentselected ~ winner_percent + sq_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey[mp.survey$information_votes==0,])  
h1.all = clogit(as.formula(paste("incumbentselected ~ winner_percent + sq_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_votes==0,])  
h1.all.controls = clogit(as.formula(paste("incumbentselected ~ winner_percent + sq_winner_percent", this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_votes==0,])  


sg=capture.output(stargazer(h1.all, h1.all.controls, h1.c, h1.mp, type = "latex", 
          out=paste("./Output/tab_votes_non_linear.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Effect of Incumbent Votes on School Selection with Non-Linear Effects",
          order=c("^z_winner_percent$", "^sq_winner_percent$"),
          keep=c("^z_winner_percent$", "^sq_winner_percent$"),
          covariate.labels = c(labelme("winner_percent"), paste(labelme("winner_percent"), "Squared")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_votes_non_linear", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. It is intended to assess whether there are non-linear effects of incumbent votes. Sample excludes maps with voting information. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_votes_non_linear_full}).}"), "tab_votes_non_linear.tex", supress_output=F)


sg=capture.output(stargazer(h1.all, h1.all.controls, h1.c, h1.mp, type = "latex", 
          out=paste("./Output/tab_votes_non_linear_full.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Effect of Incumbent Votes on School Selection with Non-Linear Effects",
          order=c("^z_winner_percent$", "^sq_z_winner_percent$"),
          covariate.labels = c(labelme("winner_percent"), paste(labelme("winner_percent"), "Squared")),
          no.space=TRUE,
          label=paste("tab_votes_non_linear_full", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. It is intended to assess whether there are non-linear effects of incumbent votes. Sample excludes maps with voting information. Standard errors are clustered on politician.}"),"tab_votes_non_linear_full.tex", supress_output=F)


m1.c = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent + information_votes*sq_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)  
m1.mp = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent + information_votes*sq_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m1.pooled = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent + information_votes*sq_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.pooled.controls = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent + information_votes*sq_winner_percent", this.controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)  


sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, type = "latex", 
          out=paste("./Output/tab_information_votes_non_linear.tex", sep=""), 
          column.labels = c("All Surveys","with Controls"),          
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Political Information with Non-Linear Voting Effects",
          order=c("^information_votes:z_winner_percent$", "^information_votes:sq_winner_percent$", "^z_winner_percent$", "^sq_winner_percent$"),
          keep=c("^information_votes:z_winner_percent$", "^information_votes:sq_winner_percent$", "^z_winner_percent$", "^sq_winner_percent$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_votes",]$label, labels.all[labels.all$varname=="winner_percent",]$label, sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_votes",]$label, paste(labels.all[labels.all$varname=="winner_percent",]$label, "Squared"), sep="*\n"),
                               labels.all[labels.all$varname=="winner_percent",]$label,
                               paste(labels.all[labels.all$varname=="winner_percent",]$label, "Squared")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_votes_non_linear", sep=""),
          table.placement = "H",
          add.lines=list(c("N Maps", summary(m1.pooled)$nevent, summary(m1.pooled.controls)$nevent), 
                         c("N Schools", summary(m1.pooled)$n, summary(m1.pooled.controls)$n))
          
))


stargazer_print(sg, paste0("\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. It is intended to assess whether there are non-linear effects of incumbent votes. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_information_votes_non_linear_full}).}"), "tab_information_votes_non_linear.tex", supress_output=F)

                
sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, type = "latex", 
          out=paste("./Output/tab_information_votes_non_linear_full.tex", sep=""), 
          column.labels = c("All Surveys","with Controls"),          
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Political Information with Non-Linear Voting Effects",
          order=c("^information_votes:z_winner_percent$", "^information_votes:sq_winner_percent$", "^z_winner_percent$", "^sq_winner_percent$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_votes",]$label, labels.all[labels.all$varname=="winner_percent",]$label, sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_votes",]$label, paste(labels.all[labels.all$varname=="winner_percent",]$label, "Squared"), sep="*\n"),
                               labels.all[labels.all$varname=="winner_percent",]$label,
                               paste(labels.all[labels.all$varname=="winner_percent",]$label, "Squared")),
          no.space=TRUE,
          label=paste("tab_information_votes_non_linear_full", sep=""),
          table.placement = "H",
          add.lines=list(c("N Maps", summary(m1.pooled)$nevent, summary(m1.pooled.controls)$nevent), 
                         c("N Schools", summary(m1.pooled)$n, summary(m1.pooled.controls)$n))
          
))

stargazer_print(sg, paste0("\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. It is intended to assess whether there are non-linear effects of incumbent votes. Standard errors are clustered on politician.}"), "tab_information_votes_non_linear_full.tex", supress_output=F)


all.surveys$sq_z_ps_victory_margin= all.surveys$z_ps_victory_margin^2
c.survey$sq_z_ps_victory_margin= c.survey$z_ps_victory_margin^2
mp.survey$sq_z_ps_victory_margin= mp.survey$z_ps_victory_margin^2

this.controls=sub("winner_percent_imp \\+", "", controls)

h1.c = clogit(as.formula(paste("incumbentselected ~ z_ps_victory_margin + sq_z_ps_victory_margin + strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_votes==0,])  
h1.mp = clogit(as.formula(paste("incumbentselected ~ z_ps_victory_margin + sq_z_ps_victory_margin + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey[mp.survey$information_votes==0,])  
h1.all1 = clogit(as.formula(paste("incumbentselected ~ z_ps_victory_margin  + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_votes==0,])  
h1.all2 = clogit(as.formula(paste("incumbentselected ~ z_ps_victory_margin + sq_z_ps_victory_margin + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_votes==0,])  
h1.all.controls = clogit(as.formula(paste("incumbentselected ~ z_ps_victory_margin + sq_z_ps_victory_margin", this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_votes==0,])  


sg=capture.output(stargazer(h1.all1, h1.all2, h1.all.controls, h1.c, h1.mp, type = "latex", 
          out=paste("./Output/tab_vm_non_linear.tex", sep=""), 
          column.labels = c("All Surveys", "All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Effect of Incumbent Votes on School Selection with Non-Linear Effects",
          order=c("^z_ps_victory_margin$", "^sq_z_ps_victory_margin$"),
          keep=c("^z_ps_victory_margin$", "^sq_z_ps_victory_margin$"),
          covariate.labels = c(labelme("ps_victory_margin"), paste(labelme("ps_victory_margin"), "Squared")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_vm_non_linear", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{6}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. It is intended to assess whether there are non-linear effects of victory margin. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_vm_non_linear_full}).}"), "tab_vm_non_linear.tex", supress_output=F)


sg=capture.output(stargazer(h1.all1, h1.all2, h1.all.controls, h1.c, h1.mp, type = "latex", 
          out=paste("./Output/tab_vm_non_linear_full.tex", sep=""), 
          column.labels = c("All Surveys", "All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Effect of Incumbent Votes on School Selection with Non-Linear Effects",
          order=c("^z_ps_victory_margin$", "^sq_z_ps_victory_margin$"),
          covariate.labels = c(labelme("ps_victory_margin"), paste(labelme("ps_victory_margin"), "Squared")),
          no.space=TRUE,
          label=paste("tab_vm_non_linear_full", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{6}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. It is intended to assess whether there are non-linear effects of victory margin. Standard errors are clustered on politician.}"), "tab_vm_non_linear_full.tex", supress_output=F)


m1.c = clogit(as.formula(paste("incumbentselected ~ information_votes*z_ps_victory_margin + information_votes*sq_z_ps_victory_margin + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)  
m1.mp = clogit(as.formula(paste("incumbentselected ~ information_votes*z_ps_victory_margin + information_votes*sq_z_ps_victory_margin + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m1.pooled1 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_ps_victory_margin + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m1.pooled2 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_ps_victory_margin + information_votes*sq_z_ps_victory_margin + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.pooled.controls = clogit(as.formula(paste("incumbentselected ~ information_votes*z_ps_victory_margin + information_votes*sq_z_ps_victory_margin", this.controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)  


sg=capture.output(stargazer(m1.pooled1,m1.pooled2, m1.pooled.controls, type = "latex", 
          out=paste("./Output/tab_information_vm_non_linear.tex", sep=""), 
          column.labels = c("All Surveys","All Surveys","with Controls"),          
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Political Information with Non-Linear Voting Effects",
          order=c("^information_votes:z_ps_victory_margin$", "^information_votes:sq_z_ps_victory_margin$", "^z_ps_victory_margin$", "^sq_z_ps_victory_margin$"),
          keep=c("^information_votes:z_ps_victory_margin$", "^information_votes:sq_z_ps_victory_margin$", "^z_ps_victory_margin$", "^sq_z_ps_victory_margin$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_votes",]$label, labels.all[labels.all$varname=="ps_victory_margin",]$label, sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_votes",]$label, paste(labels.all[labels.all$varname=="ps_victory_margin",]$label, "Squared"), sep="*\n"),
                               labels.all[labels.all$varname=="ps_victory_margin",]$label,
                               paste(labels.all[labels.all$varname=="ps_victory_margin",]$label, "Squared")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_vm_non_linear", sep=""),
          table.placement = "H",
          add.lines=list(c("N Maps", summary(m1.pooled1)$nevent, summary(m1.pooled2)$nevent,summary(m1.pooled)$nevent), 
                         c("N Schools", summary(m1.pooled1)$n, summary(m1.pooled2)$n, summary(m1.pooled.controls)$n))))

stargazer_print(sg, paste0("\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. It is intended to assess whether there are non-linear effects of victory margin. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_vm_non_linear_full}).}"), "tab_information_vm_non_linear.tex", supress_output=F)


sg=capture.output(stargazer(m1.pooled1,m1.pooled2, m1.pooled.controls, type = "latex", 
          out=paste("./Output/tab_information_vm_non_linear_full.tex", sep=""), 
          column.labels = c("All Surveys","All Surveys","with Controls"),          
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Political Information with Non-Linear Voting Effects",
          order=c("^information_votes:z_ps_victory_margin$", "^information_votes:sq_z_ps_victory_margin$", "^z_ps_victory_margin$", "^sq_z_ps_victory_margin$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_votes",]$label, labels.all[labels.all$varname=="ps_victory_margin",]$label, sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_votes",]$label, paste(labels.all[labels.all$varname=="ps_victory_margin",]$label, "Squared"), sep="*\n"),
                               labels.all[labels.all$varname=="ps_victory_margin",]$label,
                               paste(labels.all[labels.all$varname=="ps_victory_margin",]$label, "Squared")),
          no.space=TRUE,
          label=paste("tab_information_vm_non_linear_full", sep=""),
          table.placement = "H",
          add.lines=list(c("N Maps", summary(m1.pooled1)$nevent, summary(m1.pooled2)$nevent,summary(m1.pooled)$nevent), 
                         c("N Schools", summary(m1.pooled1)$n, summary(m1.pooled2)$n, summary(m1.pooled.controls)$n))))

stargazer_print(sg, paste0("\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. It is intended to assess whether there are non-linear effects of victory margin. Standard errors are clustered on politician.}"), "tab_information_vm_non_linear_full.tex", supress_output=F)

```


\section{Effects of the Aid Information Treatment}


\subsection{Conditional Logit Estimates of the Aid Information Treatment (Figure 9, Table S10-S11, Figure S16, Table S36, Table 3)}

```{r information_aid_clogit, echo=FALSE, message=FALSE, warning=FALSE, eval=T, results='asis'}

this.controls=gsub("\\+ past_aid_project","", controls)
this.controls=gsub("\\+ number_aid_categories","", this.controls)

this.controls.labels=controls.labels[controls.labels != "Aid Project Count"]
this.controls.labels=controls.labels[controls.labels != "Aid Good Types"]


results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, ate_se=NA)

i=0
model_id=0


m1.c = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
m1.mp = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m1.pooled = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.pooled.controls = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project ", this.controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)  


models <- list(m1.pooled, m1.pooled.controls, m1.c, m1.mp)
names <- c(labelme("past_aid_project"), 
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n with Controls"),
                 paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n only Councillors"),
                       paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n only MPs") )


for(m in models){
  
  this.var="z_past_aid_project"
  this.treat="information_aid"
  
  i=nrow(results)+1
  model_id=model_id+1
    
  t=1
  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
  results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
}



m2.c = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)  
m2.mp = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m2.pooled = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m2.pooled.controls = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories", this.controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)  



models <- list(m2.pooled, m2.pooled.controls, m2.c, m2.mp)
names <- c(labelme("number_aid_categories"), 
           paste(labels.all[labels.all$varname=="number_aid_categories",]$label, "\n with Controls"),
                 paste(labels.all[labels.all$varname=="number_aid_categories",]$label, "\n only Councillors"),
                       paste(labels.all[labels.all$varname=="number_aid_categories",]$label, "\n only MPs") )

model_id=0
for(m in models){
  
  this.var="z_number_aid_categories"
  this.treat="information_aid"
  
  i=nrow(results)+1
  model_id=model_id+1
    
  t=1
  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
  results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|z|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
}



all.surveys$trans_temp=all.surveys$transparency_all
m1.pooled.transparency = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*trans_temp + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
all.surveys$trans_temp=all.surveys$transparency_donor
m1.pooled.transparencydonor = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*trans_temp + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
all.surveys$trans_temp=all.surveys$transparency_radio
m1.pooled.transparencyradio = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*trans_temp + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.pooled.transparency.gt = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*trans_temp + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.pooled.transparency, m1.pooled.transparencydonor, m1.pooled.transparencyradio, m1.pooled.transparency.gt)
names <- c(paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Transparency Condition"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Donor Transparency"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Radio Transparency"),
          paste(labels.all[labels.all$varname=="number_aid_categories",]$label, "\n Transparency Condition")
           )
mvar=c("z_past_aid_project", "z_past_aid_project", "z_past_aid_project", "z_number_aid_categories")


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var=mvar[model_id]
  this.treat="information_aid"
  this.mediator="trans_temp"
  
  t=1
  k=0

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
   results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

      
}


m1.pooled.popdensity = clogit(as.formula(paste("incumbentselected ~ information_aid*z_pop_per_hectacre*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.pooled.popdensity, m1.pooled.popdensity)
names <- c(paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Low Pop Density"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n High Pop Density")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_past_aid_project"
  this.treat="information_aid"
  this.mediator="z_pop_per_hectacre"
  
  t=1
  
  if(model_id==1){ k=-1}
  if(model_id==2){ k=1}

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
   results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.mediator, ":", this.var), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.mediator, ":",this.var )]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.mediator, ":", this.var)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k^2*vcov(m)[paste0(this.mediator, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
    results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.mediator, ":", this.var), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.mediator, ":", this.var)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k^2*vcov(m)[paste0(this.mediator, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]
      )
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

      
}


m1.pooled.distance = clogit(as.formula(paste("incumbentselected ~ information_aid*z_school_home_distance*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

models <- list(m1.pooled.distance, m1.pooled.distance)
names <- c(paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Near to Hometown"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Far from Hometown")
           )

s=sd(all.surveys$z_school_home_distance, na.rm=T)
mn=mean(all.surveys$z_school_home_distance, na.rm=T)


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_past_aid_project"
  this.treat="information_aid"
  this.mediator="z_school_home_distance"
  
  t=1
  if(model_id==1){ k=mn-s}
  if(model_id==2){ k=mn+s}

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
     results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.mediator, ":", this.var), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.mediator, ":",this.var )]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.mediator, ":", this.var)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k^2*vcov(m)[paste0(this.mediator, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
    results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.mediator, ":", this.var), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.mediator, ":", this.var)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k^2*vcov(m)[paste0(this.mediator, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]
      )
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

      
}

m1.pooled.knowledge = clogit(as.formula(paste("incumbentselected ~ information_aid*donor_knowledge*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m1.pooled.knowledge2 = clogit(as.formula(paste("incumbentselected ~ information_aid*donor_knowledge*z_number_aid_categories + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m1.pooled.knowledge.controls = clogit(as.formula(paste("incumbentselected ~ information_aid*donor_knowledge*z_past_aid_project", this.controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m1.pooled.knowledge2.controls = clogit(as.formula(paste("incumbentselected ~ information_aid*donor_knowledge*z_past_aid_project", this.controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.pooled.knowledge, m1.pooled.knowledge)
names <- c(paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Low Knowledge"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n High Knowledge")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_past_aid_project"
  this.treat="information_aid"
  this.mediator="donor_knowledge"
  
  t=1
  if(model_id==1){ k=0}
  if(model_id==2){ k=1}

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
     results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.mediator, ":", this.var), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.mediator, ":",this.var )]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.mediator, ":", this.var)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k^2*vcov(m)[paste0(this.mediator, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
    results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.mediator, ":", this.var), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.mediator, ":", this.var)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]+
          2*t*k^2*vcov(m)[paste0(this.mediator, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)]
      )
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

      
}




results$exp_estimate = exp(results$estimate)
results=results[!is.na(results$model),]

results=results[order(results$model, results$model),]
results=results[!is.na(results$estimate),]

results$estimate=exp(results$estimate)


results.aid=results[results$term %in% c("Aid Project Count", "Aid Project Count \n with Controls","Aid Good Types","Aid Project Count \n Transparency Condition", "Aid Good Types \n Transparency Condition"),]



p=dwplot(results.aid, 
                  dot_args = list(aes(shape = as.character(results.aid$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.aid[results.aid$model=="Treatment",])), x = rep(0.42, nrow(results.aid[results.aid$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.aid[results.aid$model=="Treatment",]$p.value,3),2))), size=3)+
  theme_bw() + xlab("Marginal Effect\n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.69, 0.03),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.1, r=0.1, t=0.1,b=0.1, unit='cm'),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(0.40, 1.85))+
    scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
    guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend



pdf("./Output/aid_treatment_plot.pdf",width=5,height=3)
p
dev.off()
p
cat(paste("\n", sep=""))

results.aid=results[results$term %in% c("Aid Project Count \n High Knowledge", "Aid Project Count \n Low Knowledge"),]


p=dwplot(results.aid, 
                  dot_args = list(aes(shape = as.character(results.aid$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.aid[results.aid$model=="Treatment",])), x = rep(0.42, nrow(results.aid[results.aid$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.aid[results.aid$model=="Treatment",]$p.value,3),2))), size=3)+
  theme_bw() + xlab("Marginal Effect\n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.69, 0.03),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.1, r=0.1, t=0.1,b=0.1, unit='cm'),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(0.40, 1.85))+
    scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
    guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend


pdf("./Output/aid_treatment_plot_knowledge.pdf",width=5,height=3)
p
dev.off()
p
cat(paste("\n", sep=""))



sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, m2.pooled,m2.pooled.controls, type = "latex", 
          out=paste("./Output/tab_information_aid.tex", sep=""), 
          column.labels = NULL,
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Foreign Aid Information on School Selection",
          order=c("^information_aid:z_past_aid_project$", "^z_past_aid_project$", "^information_aid:z_number_aid_categories$", "^z_number_aid_categories$"),
          keep=c("^information_aid:z_past_aid_project$", "^z_past_aid_project$", "^information_aid:z_number_aid_categories$", "^z_number_aid_categories$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_aid",]$label, labels.all[labels.all$varname=="past_aid_project",]$label, sep="*\n"), labels.all[labels.all$varname=="past_aid_project",]$label,
                               paste(labels.all[labels.all$varname=="information_aid",]$label, labels.all[labels.all$varname=="number_aid_categories",]$label, sep="*\n"), labels.all[labels.all$varname=="number_aid_categories",]$label
                               ),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_aid", sep=""),
          table.placement = "H",
          add.lines=list(c("Controls", "No", "Yes", "No", "Yes"),
            c("N Maps", summary(m1.pooled)$nevent, summary(m1.pooled.controls)$nevent, summary(m2.pooled)$nevent, summary(m2.pooled.controls)$nevent), c("N Schools", summary(m1.pooled)$n, summary(m1.pooled.controls)$n, summary(m2.pooled)$n, summary(m2.pooled.controls)$n))
          
))

stargazer_print(sg, "\\multicolumn{5}{p{0.9\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. See SI 3.3, Table S10 for complete model results.}", "tab_information_aid.tex")


#with controls for SI

sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, m2.pooled, m1.c, m1.mp, type = "latex", 
          out=paste("./Output/tab_information_aid_expanded1.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Alternate Coding", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 9 (part 1)",
          order=c("^information_aid:z_past_aid_project$", "^z_past_aid_project$", "^information_aid:z_number_aid_categories$", "^z_number_aid_categories$", "^information_aid$", this.controls),
          keep=c("*"),
          covariate.labels = c(labelme("information_aid:z_past_aid_project"), labelme("past_aid_project"), labelme("information_aid:z_number_aid_categories"), labelme("number_aid_categories"), labelme("information_aid"), this.controls.labels),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_aid_expanded1", sep=""),
          table.placement = "H"
          
))
stargazer_print(sg, "\\multicolumn{6}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_aid_expanded1.tex")





sg=capture.output(stargazer(m1.pooled.transparency, type = "latex", 
          out=paste("./Output/tab_information_aid_expanded2.tex", sep=""), 
          column.labels = c("Transparency Interactions"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 9 (part 2)",
          order=c("^information_aid:z_past_aid_project:trans_temp$", 
                  "^information_aid:z_past_aid_project$",
                  "^z_past_aid_project:trans_temp$", 
                  "^information_aid:trans_temp$", 
                  "^z_past_aid_project$", 
                  "information_aid"),
          keep="*",
          covariate.labels = c(labelme("information_aid:z_past_aid_project:transparency_all"),
                               labelme("information_aid:z_past_aid_project"),
                               labelme("past_aid_project:transparency_all"),
                               labelme("information_aid:transparency_all"),
                               labelme("past_aid_project"), 
                               labelme("information_aid"), 
                               labelme("transparency_all")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_aid_expanded2", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{2}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_aid_expanded2.tex")





sg=capture.output(stargazer(m1.pooled.knowledge,m1.pooled.knowledge.controls, type = "latex", 
          out=paste("./Output/tab_information_aid_knowledge.tex", sep=""), 
          column.labels = c("without controls","with controls"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interactions of Aid Information Treatment with Aid Knowledge",
          order=c("^information_aid:donor_knowledge:z_past_aid_project$",
                  "^information_aid:z_past_aid_project$",
                  "^donor_knowledge:z_past_aid_project$",
                  "^information_aid:donor_knowledge$", 
                  "^z_past_aid_project$", 
                  "information_aid", 
                  "donor_knowledge"),
          keep=c("^information_aid:donor_knowledge:z_past_aid_project$",
                  "^information_aid:z_past_aid_project$",
                  "^donor_knowledge:z_past_aid_project$",
                  "^information_aid:donor_knowledge$", 
                  "^z_past_aid_project$", 
                  "information_aid", 
                  "donor_knowledge"),
          
          covariate.labels = c(labelme("information_aid:donor_knowledge:z_past_aid_project"),
                               labelme("information_aid:z_past_aid_project"),
                               labelme("donor_knowledge:z_past_aid_project"),
                               labelme("information_aid:donor_knowledge"), 
                               labelme("past_aid_project"), 
                               labelme("information_aid"), 
                               labelme("donor_knowledge")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_aid_knowledge", sep=""),
          table.placement = "H"
          
))


stargazer_print(sg, paste0("\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_information_aid_knowledge_full})}"), "tab_information_aid_knowledge.tex", supress_output=F)



sg=capture.output(stargazer(m1.pooled.knowledge,m1.pooled.knowledge.controls, type = "latex", 
          out=NULL,
          column.labels = c("without controls","with controls"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interactions of Aid Information Treatment with Aid Knowledge, Full Model",
          order=c("^information_aid:donor_knowledge:z_past_aid_project$",
                  "^information_aid:z_past_aid_project$",
                  "^donor_knowledge:z_past_aid_project$",
                  "^information_aid:donor_knowledge$", 
                  "^z_past_aid_project$", 
                  "information_aid", 
                  "donor_knowledge"),
          covariate.labels = c(labelme("information_aid:donor_knowledge:z_past_aid_project"),
                               labelme("information_aid:z_past_aid_project"),
                               labelme("donor_knowledge:z_past_aid_project"),
                               labelme("information_aid:donor_knowledge"), 
                               labelme("past_aid_project"), 
                               labelme("information_aid"), 
                               labelme("donor_knowledge")),
          keep="*",
          no.space=TRUE,
          label=paste("tab_information_aid_knowledge_full", sep=""),
          table.placement = "H"
          
))


stargazer_print(sg, paste0("\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}"), "tab_information_aid_knowledge_full.tex", supress_output=F)


```


\subsection{Linear Probability Model Estimates of the Aid Information Treatment (Figure S9)}
```{r information_aid_lpm, message=FALSE, warning=FALSE, results='asis',eval=T, echo=FALSE}


this.controls=gsub(" \\+  past_aid_project","", controls)
this.controls=gsub(" \\+  number_aid_categories","", controls)

this.controls.labels=controls.labels[controls.labels != "Aid Project Count"]
this.controls.labels=controls.labels[controls.labels != "Aid Good Types"]

all.surveys$number_aid_categories=all.surveys$z_number_aid_categories
all.surveys$past_aid_project=all.surveys$z_past_aid_project
c.survey$number_aid_categories=c.survey$z_number_aid_categories
c.survey$past_aid_project=c.survey$z_past_aid_project
mp.survey$number_aid_categories=mp.survey$z_number_aid_categories
mp.survey$past_aid_project=mp.survey$z_past_aid_project

results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, ate_se=NA)

i=0
model_id=0


m1.c = felm(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project | map_id |0|resp_id")), c.survey)  
m1.mp = felm(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project | map_id |0|resp_id")),  mp.survey)
m1.pooled = felm(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project | map_id |0|resp_id")), all.surveys)
m1.pooled.controls = felm(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project",this.controls," | map_id |0|resp_id")), all.surveys)  



models <- list(m1.pooled, m1.pooled.controls, m1.c, m1.mp)
names <- c(labelme("past_aid_project"), 
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n with Controls"),
                 paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n only Councillors"),
                       paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n only MPs") )


for(m in models){
  
  this.var="z_past_aid_project"
  this.treat="information_aid"
  
  i=nrow(results)+1
  model_id=model_id+1
    
  t=1
  
  results[i,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "Cluster s.e."]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|t|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=(results[i,]$estimate-qt(0.975,df=m$N-1)*results[i,]$robust.se)
  results[i,]$conf.high=(results[i,]$estimate +qt(0.975,df=m$N-1)*results[i,]$robust.se)
  
  t=0
  results[i+1,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "Cluster s.e."]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|t|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=(results[i+1,]$estimate-qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=(results[i+1,]$estimate +qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
}



m2.c = felm(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories | map_id |0|resp_id")), c.survey)  
m2.mp = felm(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories | map_id |0|resp_id")), mp.survey)
m2.pooled = felm(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories | map_id |0|resp_id")), all.surveys)
m2.pooled.controls = felm(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories",this.controls,"  | map_id |0|resp_id")), all.surveys)  




models <- list(m2.pooled, m2.pooled.controls, m2.c, m2.mp)
names <- c(labelme("number_aid_categories"), 
           paste(labels.all[labels.all$varname=="number_aid_categories",]$label, "\n with Controls"),
                 paste(labels.all[labels.all$varname=="number_aid_categories",]$label, "\n only Councillors"),
                       paste(labels.all[labels.all$varname=="number_aid_categories",]$label, "\n only MPs") )

model_id=0
for(m in models){
  
  this.var="z_number_aid_categories"
  this.treat="information_aid"
  
  i=nrow(results)+1
  model_id=model_id+1
    
  t=1
  
  results[i,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t
  results[i,]$robust.se = sqrt(coef(summary(m))[this.var, "Cluster s.e."]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i,]$term=names[model_id]
  results[i,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|t|)"]
  results[i,]$model="Treatment"
  results[i,]$conf.low=(results[i,]$estimate-qt(0.975,df=m$N-1)*results[i,]$robust.se)
  results[i,]$conf.high=(results[i,]$estimate +qt(0.975,df=m$N-1)*results[i,]$robust.se)
  
  t=0
  results[i+1,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t
  results[i+1,]$robust.se = sqrt(coef(summary(m))[this.var, "Cluster s.e."]^2 + t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 + 2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)])
  results[i+1,]$term=names[model_id]
  results[i+1,]$p.value=coef(summary(m))[paste0(this.treat, ":", this.var), "Pr(>|t|)"]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=(results[i+1,]$estimate-qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=(results[i+1,]$estimate +qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
}



all.surveys$trans_temp=all.surveys$transparency_all
m1.pooled.transparency = felm(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*trans_temp  | map_id |0|resp_id")), all.surveys)
all.surveys$trans_temp=all.surveys$transparency_donor
m1.pooled.transparencydonor = felm(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*trans_temp  | map_id |0|resp_id")), all.surveys)
all.surveys$trans_temp=all.surveys$transparency_radio
m1.pooled.transparencyradio = felm(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*trans_temp  | map_id |0|resp_id")),  all.surveys)
m1.pooled.transparency.gt = felm(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*trans_temp  | map_id |0|resp_id")),  all.surveys)


models <- list(m1.pooled.transparency, m1.pooled.transparencydonor, m1.pooled.transparencyradio, m1.pooled.transparency.gt)
names <- c(paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Transparency Condition"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Donor Transparency"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Radio Transparency"),
          paste(labels.all[labels.all$varname=="number_aid_categories",]$label, "\n Transparency Condition")
           )
mvar=c("z_past_aid_project", "z_past_aid_project", "z_past_aid_project", "z_number_aid_categories")


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var=mvar[model_id]
  this.treat="information_aid"
  this.mediator="trans_temp"
  
  t=1
  k=0

  
  results[i,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator),]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator),]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var),]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator),]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "Cluster s.e."]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "Cluster s.e."]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "Cluster s.e."]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "Cluster s.e."]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=(results[i,]$estimate-qt(0.975,df=m$N-1)*results[i,]$robust.se)
  results[i,]$conf.high=(results[i,]$estimate +qt(0.975,df=m$N-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var,] + m$coefficients[paste0(this.treat, ":", this.var),]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator),]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator),]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "Cluster s.e."]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "Cluster s.e."]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "Cluster s.e."]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "Cluster s.e."]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=(results[i+1,]$estimate-qt(0.975,df=m$N-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=(results[i+1,]$estimate +qt(0.975,df=m$N-1)*results[i+1,]$robust.se)

    results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$N-1, lower=FALSE)

}



results=results[!is.na(results$model),]

results=results[order(results$model, results$model),]
results=results[!is.na(results$estimate),]


results.aid=results


results.aid=results.aid[results.aid$term %in% c("Aid Project Count", "Aid Project Count \n with Controls","Aid Good Types","Aid Project Count \n Transparency Condition", "Aid Good Types \n Transparency Condition"),]

p=dwplot(results.aid, 
         dot_args = list(aes(shape = as.character(results.aid$model))),
       vline = geom_vline(xintercept = 0, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.aid[results.aid$model=="Treatment",])), x = rep(-0.22, nrow(results.aid[results.aid$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.aid[results.aid$model=="Treatment",]$p.value,4),2))), size=3)+
  theme_bw() + xlab("Marginal Effect \n(Linear Probability Model)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.70, 0.031),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.1, r=0.1, t=0.1,b=0.1, unit='cm'),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(-0.25, 0.25))+
  scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
  guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend



pdf("./Output/aid_treatment_plot_lpm.pdf",width=5,height=4)
p
dev.off()
p
cat(paste("\n", sep=""))


sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, m2.pooled, type = "latex", 
          out=paste("./Output/tab_information_aid_lpm.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Alternate Coding"),
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Foreign Aid Information, Linear Model",
          order=c("^information_aid:z_past_aid_project$", "^z_past_aid_project$", "^information_aid:z_number_aid_categories$", "^z_number_aid_categories$"),
          keep=c("^information_aid:z_past_aid_project$", "^z_past_aid_project$", "^information_aid:z_number_aid_categories$", "^z_number_aid_categories$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_aid",]$label, labels.all[labels.all$varname=="past_aid_project",]$label, sep="*\n"), labels.all[labels.all$varname=="past_aid_project",]$label,
                               paste(labels.all[labels.all$varname=="information_aid",]$label, labels.all[labels.all$varname=="number_aid_categories",]$label, sep="*\n"), labels.all[labels.all$varname=="number_aid_categories",]$label
                               ),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_aid_lpm", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients from linear regressions on school selection. Standard errors are clustered on politician.}", "tab_information_aid_lpm.tex", relabelr2=F)





#with controls for SI

sg=capture.output(stargazer(m1.pooled, m1.pooled.controls, m2.pooled, m1.c, m1.mp, type = "latex", 
          out=paste("./Output/tab_information_aid_expanded1_lpm.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Alternate Coding", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 9 (part 1), Linear Model",
          order=c("^information_aid:z_past_aid_project$", "^z_past_aid_project$", "^information_aid:z_number_aid_categories$", "^z_number_aid_categories$", "^information_aid$", this.controls),
          keep=c("*"),
          covariate.labels = c(labelme("information_aid:z_past_aid_project"), labelme("past_aid_project"), labelme("information_aid:z_number_aid_categories"), labelme("number_aid_categories"), labelme("information_aid"), this.controls.labels),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_aid_expanded1_lpm", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{6}{p{\\textwidth}}{This table shows the coefficients from linear regressions on school selection. Standard errors are clustered on politician.}", "tab_information_aid_expanded1_lpm.tex", relabelr2=F)



sg=capture.output(stargazer(m1.pooled.transparency, type = "latex", 
          out=paste("./Output/tab_information_aid_expanded2_lpm.tex", sep=""), 
          column.labels = c("Transparency Interactions"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 9 (part 2), Linear Model",
          order=c("^information_aid:z_past_aid_project:trans_temp$", 
                  "^information_aid:z_past_aid_project$",
                  "^z_past_aid_project:trans_temp$", 
                  "^information_aid:trans_temp$", 
                  "^z_past_aid_project$", 
                  "information_aid"),
          keep="*",
          covariate.labels = c(labelme("information_aid:z_past_aid_project:transparency_all"),
                               labelme("information_aid:z_past_aid_project"),
                               labelme("past_aid_project:transparency_all"),
                               labelme("information_aid:transparency_all"),
                               labelme("past_aid_project"), 
                               labelme("information_aid"), 
                               labelme("transparency_all")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_information_aid_expanded2_lpm", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{2}{p{\\textwidth}}{This table shows the coefficients from linear regressions on school selection. Standard errors are clustered on politician.}", "tab_information_aid_expanded2_lpm.tex", relabelr2=F)




```

\subsection{Heterogenous Effects of the Aid Information Treatment (Figure S5)}

```{r information_aid_het, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, ate_se=NA)

i=0
model_id=0

all.surveys$genderM=ifelse(all.surveys$gender=="Male", 1, 0)
m1.gender = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*genderM + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

models <- list(m1.gender, m1.gender)
names <- c(paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Male Politicians"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Female Politicians")
           )

model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_past_aid_project"
  this.treat="information_aid"
  this.mediator="genderM"
  
  t=1
  k=model_id-1

  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}


all.surveys$timeliving=NA
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("Donâ<U+0080><U+0099>t know", "Decline to answer"), NA, all.surveys$timeliving)
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("Less than 5 years", "5 to 10 years"), 0, all.surveys$timeliving)
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("More than 10 years"), 1, all.surveys$timeliving)
all.surveys$timeliving=ifelse(all.surveys$survey_timeliving %in% c("All of my life"), 1, all.surveys$timeliving)

m1.timeliving = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*timeliving + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


models <- list(m1.timeliving, m1.timeliving)
names <- c(paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Lived in constituency < 10 years"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Lived in constituency > 10 years")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_past_aid_project"
  this.treat="information_aid"
  this.mediator="timeliving"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  
    results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}



m1.contest = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*contest_electionYes + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

models <- list(m1.contest, m1.contest)
names <- c(paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Contesting election=Yes"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Contesting election=No or Unsure")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_past_aid_project"
  this.treat="information_aid"
  this.mediator="contest_electionYes"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)

    results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}


m1.useful = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*useful + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

models <- list(m1.useful, m1.useful, m1.useful)
names <- c(paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Information=Not very useful"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Information=Somewhat useful"),
           paste(labels.all[labels.all$varname=="past_aid_project",]$label, "\n Information=Very useful")
           )


model_id=0
for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_past_aid_project"
  this.treat="information_aid"
  this.mediator="useful"
  
  t=1
  k=model_id-1

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)])
          
  
  results[i,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i,]$term=names[model_id]
  results[i,]$model="Treatment"
  results[i,]$conf.low=exp(results[i,]$estimate-qt(0.975,df=m$n-1)*results[i,]$robust.se)
  results[i,]$conf.high=exp(results[i,]$estimate +qt(0.975,df=m$n-1)*results[i,]$robust.se)
  
  t=0
   results[i+1,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.var, ":", this.mediator)]*t*k+
    m$coefficients[paste0(this.var, ":", this.mediator)]*k
  
  results[i+1,]$robust.se = sqrt(
        coef(summary(m))[this.var, "robust se"]^2 + 
          t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
          k^2*coef(summary(m))[paste0(this.var, ":", this.mediator), "robust se"]^2 +
          k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var, ":", this.mediator), "robust se"]^2 +
          
          2*t*vcov(m)[this.var,paste0(this.treat, ":", this.var)]+
          2*k*vcov(m)[this.var,paste0(this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[this.var,paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.var, ":", this.mediator)]+
          
          2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.var, ":", this.mediator)]+
          2*t*k^2*vcov(m)[paste0(this.var, ":", this.mediator), paste0(this.treat,  ":", this.var, ":", this.mediator)]
      )
  
  results[i+1,]$term=names[model_id]
  results[i+1,]$model="Control"
  results[i+1,]$conf.low=exp(results[i+1,]$estimate-qt(0.975,df=m$n-1)*results[i+1,]$robust.se)
  results[i+1,]$conf.high=exp(results[i+1,]$estimate +qt(0.975,df=m$n-1)*results[i+1,]$robust.se)

    results[i:(i+1),]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)

}




results$exp_estimate = exp(results$estimate)
results=results[!is.na(results$model),]

results=results[order(results$model, results$model),]
results=results[!is.na(results$estimate),]
results$estimate=results$exp_estimate

results.aid=results



p=dwplot(results.aid, 
         dot_args = list(aes(shape = as.character(results.aid$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+
  annotate("text", y = (1:nrow(results.aid[results.aid$model=="Treatment",])), x = rep(0.05, nrow(results.aid[results.aid$model=="Treatment",])), label = paste("  p=", rev(round(signif(results.aid[results.aid$model=="Treatment",]$p.value,4),2))), size=3)+
  theme_bw() + xlab("Marginal Effect \n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.65, 0.031),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.3),
        legend.margin=margin(l = 0.1, r=0.1, t=0.1,b=0.1, unit='cm'),
        legend.title = element_blank()) +
  scale_shape_discrete(name = "model")+
  coord_cartesian(xlim=c(0, 2.6))+
  scale_color_manual(values=wes_palette(n=4, name="IsleofDogs2")[c(2,4)])+
  guides(colour = guide_legend(override.aes=list(shape=c(17,16))), shape="none") #changes shape of points in legend


pdf("./Output/aid_treatment_plot_het.pdf",width=5.6,height=4, family="Helvetica")
p
dev.off()
p
cat(paste("\n", sep=""))



sg=capture.output(stargazer(m1.contest, m1.gender, m1.timeliving, m1.useful, type = "latex", 
          out=NULL, 
          model.names=FALSE, header=FALSE, keep.stat = c("f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="The Effect of Aid Information, Heterogenous Effects",
          no.space=TRUE,
          label=paste("tab_aid_treatment_plot_het", sep=""),
          table.placement = "H")
          
)

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_aid_treatment_plot_het.tex")




```


\section{Other Treatment Effect Estimates}

\subsection{Interactions between Treatments (Tables S31, S32, S33)}
```{r interactions, message=FALSE, warning=FALSE, echo=FALSE, results='asis'}

m1 = clogit(as.formula(paste("incumbentselected ~ information_need*information_votes*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m2 = clogit(as.formula(paste("incumbentselected ~ information_need*information_aid*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m3 = clogit(as.formula(paste("incumbentselected ~ information_votes*information_need*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m4 = clogit(as.formula(paste("incumbentselected ~ information_votes*information_aid*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m5 = clogit(as.formula(paste("incumbentselected ~ information_aid*information_need*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m6 = clogit(as.formula(paste("incumbentselected ~ information_aid*information_votes*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


sg=capture.output(stargazer(m1, m2, type = "latex", 
          out=paste("./Output/tab_information_interactions_need.tex", sep=""), 
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Information Treatment Interactions with School Need Index",
          order=c("^school_need_index$","^information_need:school_need_index$","^information_votes:school_need_index$", "^information_aid:school_need_index$","^information_need:information_votes:school_need_index$", "^information_need:information_aid:school_need_index$"),
          keep=c("^school_need_index$","^information_need:school_need_index$","^information_votes:school_need_index$", "^information_aid:school_need_index$","^information_need:information_votes:school_need_index$", "^information_need:information_aid:school_need_index$"),
           covariate.labels =c(labelme("school_need_index"),labelme("information_need:school_need_index"),labelme("information_votes:school_need_index"),labelme("information_aid:school_need_index"), labelme("information_need:information_votes:school_need_index"), labelme("information_need:information_aid:school_need_index")),
                    no.space=TRUE,
          label=paste("tab_information_interactions_need", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_interactions_need.tex")


sg=capture.output(stargazer(m3, m4, type = "latex", 
          out=paste("./Output/tab_information_interactions_votes.tex", sep=""), 
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Information Treatment Interactions with Percent Votes",
           order=c("^z_winner_percent$","^information_need:z_winner_percent$","^information_votes:z_winner_percent$","^information_aid:z_winner_percent$","^information_votes:information_need:z_winner_percent$", "^information_votes:information_aid:z_winner_percent$"),
           keep=c("^z_winner_percent$","^information_need:z_winner_percent$","^information_votes:z_winner_percent$","^information_aid:z_winner_percent$","^information_votes:information_need:z_winner_percent$", "^information_votes:information_aid:z_winner_percent$"),
           covariate.labels =c(labelme("winner_percent"),labelme("information_need:z_winner_percent"),labelme("information_votes:z_winner_percent"), labelme("information_aid:z_winner_percent"),labelme("information_need:information_votes:z_winner_percent"), labelme("information_votes:information_aid:z_winner_percent")),
          no.space=TRUE,
          label=paste("tab_information_interactions_votes", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_interactions_votes.tex")


sg=capture.output(stargazer(m5, m6, type = "latex", 
          out=paste("./Output/tab_information_interactions_aid.tex", sep=""), 
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Information Treatment Interactions with Aid Projects",
           order=c("^z_past_aid_project$","^information_need:z_past_aid_project$","^information_aid:z_past_aid_project$","^information_votes:z_past_aid_project$", "^information_aid:information_need:z_past_aid_project$", "^information_aid:information_votes:z_past_aid_project$"),
           keep=c("^z_past_aid_project$","^information_need:z_past_aid_project$","^information_aid:z_past_aid_project$","^information_votes:z_past_aid_project$", "^information_aid:information_need:z_past_aid_project$", "^information_aid:information_votes:z_past_aid_project$"),
           covariate.labels =c(labelme("past_aid_project"),labelme("information_need:z_past_aid_project"),labelme("information_aid:z_past_aid_project"),labelme("information_votes:z_past_aid_project"), labelme("information_need:information_aid:z_past_aid_project"), labelme("information_aid:information_votes:z_past_aid_project")),
          no.space=TRUE,
          label=paste("tab_information_interactions_aid", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_information_interactions_aid.tex")


```


\subsection{Multiple Comparison Corrections (Figure S3, Tables S17, S18, 19)}

```{r multiplecomparison, echo=FALSE, warning=FALSE, results='asis', eval=T}


this.controls=gsub(" \\+  school_need_index","", controls)

##need information hypotheses
hb1 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hb2 = clogit(as.formula(paste("incumbentselected ~ information_need*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hb3 = clogit(as.formula(paste("incumbentselected ~ information_need*z_school_home_distance + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


results=data.frame(Hypothesis="H1. Politicians will be more likely to allocate to schools in areas with high need.", p_value_unadjusted=tidy(hb1)$p.value[3])
results=rbind(results, data.frame(Hypothesis="H2. Politicians will be be more likely to allocate to schools located in areas with higher support in the last election.", p_value_unadjusted=tidy(hb2)$p.value[3]))
results=rbind(results, data.frame(Hypothesis="H3. Politicians will be less likely to allocate to schools located in their home community or where family members attend.", p_value_unadjusted=tidy(hb3)$p.value[3]))



results=results[order(results$p_value_unadjusted),]
results$Unadjusted=results$p_value_unadjusted
results$BH=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$Bonferroni=round(p.adjust(results$p_value_unadjusted, method="bonferroni"),4)
results$p_value_unadjusted=NULL

results.need=results


##need information hypotheses
hb1 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index", this.controls, " + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hb2 = clogit(as.formula(paste("incumbentselected ~ information_need*z_winner_percent", this.controls, " + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hb3 = clogit(as.formula(paste("incumbentselected ~ information_need*any_children_attend_school", this.controls, " + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

results=data.frame(Hypothesis="H1. Politicians will be more likely to allocate to schools in areas with high need.", p_value_unadjusted=tidy(hb1)$p.value[17])
results=rbind(results, data.frame(Hypothesis="H2. Politicians will be be more likely to allocate to schools located in areas with higher support in the last election.", p_value_unadjusted=tidy(hb2)$p.value[18]))
results=rbind(results, data.frame(Hypothesis="H3. Politicians will be less likely to allocate to schools located in their home community or where family members attend.", p_value_unadjusted=tidy(hb3)$p.value[17]))

results=results[order(results$p_value_unadjusted),]
results$'Unadjusted with controls'=results$p_value_unadjusted
results$'BH with controls'=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$'Bonferroni with controls'=round(p.adjust(results$p_value_unadjusted, method="bonferroni"),4)
results$p_value_unadjusted=NULL

results.need.controls=results


##need information hypotheses, LCs
hb1 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index", " + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
hb2 = clogit(as.formula(paste("incumbentselected ~ information_need*z_winner_percent", " + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
hb3 = clogit(as.formula(paste("incumbentselected ~ information_need*any_children_attend_school", " + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)



results=data.frame(Hypothesis="H1. Politicians will be more likely to allocate to schools in areas with high need.", p_value_unadjusted=tidy(hb1)$p.value[3])
results=rbind(results, data.frame(Hypothesis="H2. Politicians will be be more likely to allocate to schools located in areas with higher support in the last election.", p_value_unadjusted=tidy(hb2)$p.value[3]))
results=rbind(results, data.frame(Hypothesis="H3. Politicians will be less likely to allocate to schools located in their home community or where family members attend.", p_value_unadjusted=tidy(hb3)$p.value[3]))


results=results[order(results$p_value_unadjusted),]
results$'Unadjusted'=results$p_value_unadjusted
results$'BH'=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$'Bonferroni'=round(p.adjust(results$p_value_unadjusted, method="bonferroni"),4)
results$p_value_unadjusted=NULL

results.need.lc=results



##need information hypotheses, MPs
hb1 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index", " + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
hb2 = clogit(as.formula(paste("incumbentselected ~ information_need*z_winner_percent", " + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
hb3 = clogit(as.formula(paste("incumbentselected ~ information_need*any_children_attend_school", " + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)



results=data.frame(Hypothesis="H1. Politicians will be more likely to allocate to schools in areas with high need.", p_value_unadjusted=tidy(hb1)$p.value[3])
results=rbind(results, data.frame(Hypothesis="H2. Politicians will be be more likely to allocate to schools located in areas with higher support in the last election.", p_value_unadjusted=tidy(hb2)$p.value[3]))
results=rbind(results, data.frame(Hypothesis="H3. Politicians will be less likely to allocate to schools located in their home community or where family members attend.", p_value_unadjusted=tidy(hb3)$p.value[3]))


results=results[order(results$p_value_unadjusted),]
results$'Unadjusted'=results$p_value_unadjusted
results$'BH'=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$'Bonferroni'=round(p.adjust(results$p_value_unadjusted, method="bonferroni"),4)
results$p_value_unadjusted=NULL

results.need.mp=results


hb1.trans = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*transparency_all + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hb2.trans = clogit(as.formula(paste("incumbentselected ~ information_need*z_winner_percent*transparency_all + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hb3.trans = clogit(as.formula(paste("incumbentselected ~ information_need*any_children_attend_school*transparency_all + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

results=data.frame(Hypothesis=integer(), p_value_unadjusted=integer())

model_id=0
for(m in list(hb1.trans, hb2.trans, hb3.trans)){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var=c("school_need_index", "z_winner_percent", "any_children_attend_school")
  this.treat="information_need"
  this.mediator="transparency_all"
  
  t=1
  k=1

  ate =  m$coefficients[paste0(this.treat, ":", this.var[model_id])]+
    m$coefficients[paste0(this.treat,  ":", this.var[model_id], ":", this.mediator)]*k
  
  ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var[model_id]), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var[model_id], ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var[model_id]), paste0(this.treat,  ":", this.var[model_id], ":", this.mediator)])
          
    results[i,]$p_value_unadjusted=2*pt(q=abs(ate/ate_se), df=m$n-1, lower=FALSE)

}



results=results[order(results$p_value_unadjusted),]
results$unadjusted_Tranparency=results$p_value_unadjusted
results$BH_Transparency=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$bonferroni_Transparency=round(p.adjust(results$p_value_unadjusted, method="bonferroni"),4)
results$p_value_unadjusted=NULL

results.need.transparency=results




xt=xtable(cbind(results.need, results.need.controls[,c(2,3,4)]),  digits=4, label="tab_multiple_comparison_need", caption="Multiple Comparison Adjustment, School Need Information", align=c(
               "p{0.01\\textwidth}|",
               "p{0.25\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|"
               ))

print(xt, file="./Output/tab_multiple_comparison_need.tex", include.rownames=FALSE,  caption.placement = "top", hline.after=c(-1, 0))
print(xt, include.rownames=FALSE,  caption.placement = "top", hline.after=c(-1, 0))


all.surveys$z_donor_frequency=(all.surveys$donor_frequency-mean(all.surveys$donor_frequency, na.rm=T))/sd(all.surveys$donor_frequency, na.rm=T)
mp.survey$z_donor_frequency=(mp.survey$donor_frequency-mean(mp.survey$donor_frequency, na.rm=T))/sd(mp.survey$donor_frequency, na.rm=T)
c.survey$z_donor_frequency=(c.survey$donor_frequency-mean(c.survey$donor_frequency, na.rm=T))/sd(c.survey$donor_frequency, na.rm=T)

this.controls=gsub(" \\+  number_aid_categories","", controls)
this.controls=gsub(" \\+  past_aid_project","", this.controls)


hd1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*z_donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd4 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd5 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
results=data.frame(Hypothesis=integer(), p_value_unadjusted=integer())
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd1)$p.value[3]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd2)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd4)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd5)$p.value[7]



results$Hypothesis=c(
  "H1. Politicians will be more likely to allocate to schools that have already benefitted from more past aid projects and where donors have provided more categories of goods.",
  "H2. Treatment effect will be greater when politicians interact frequently with donors.",
  "H3. Treatment effect will be greater where the politician did not receive a high proportion of votes.",
  "H4. Treatment effect will be greater where schools are less needy."
  )


results$'Unadjusted Aid Types'=results$p_value_unadjusted
results$'BH Aid Types'=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$'Bonferroni Aid Types'=p.adjust(results$p_value_unadjusted, method="bonferroni")
results$p_value_unadjusted=NULL

results.aid1=results


hd1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
hd2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*z_donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd4 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
hd5 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
results=data.frame(Hypothesis=integer(), p_value_unadjusted=integer())
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd1)$p.value[3]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd2)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd4)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd5)$p.value[7]

results$Hypothesis=c(
  "H1. Politicians will be more likely to allocate to schools that have already benefitted from more past aid projects and where donors have provided more categories of goods.",
  "H2. Treatment effect will be greater when politicians interact frequently with donors.",
  "H3. Treatment effect will be greater where the politician did not receive a high proportion of votes.",
  "H4. Treatment effect will be greater where schools are less needy."
  )



results$Unadjusted=results$p_value_unadjusted
results$BH=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$Bonferroni=p.adjust(results$p_value_unadjusted, method="bonferroni")
results$p_value_unadjusted=NULL

results.aid1.lc=results



hd1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
hd2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*z_donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
hd4 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
hd5 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
results=data.frame(Hypothesis=integer(), p_value_unadjusted=integer())
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd1)$p.value[3]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd2)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd4)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd5)$p.value[7]

results$Hypothesis=c(
  "H1. Politicians will be more likely to allocate to schools that have already benefitted from more past aid projects and where donors have provided more categories of goods.",
  "H2. Treatment effect will be greater when politicians interact frequently with donors.",
  "H3. Treatment effect will be greater where the politician did not receive a high proportion of votes.",
  "H4. Treatment effect will be greater where schools are less needy."
  )



results$Unadjusted=results$p_value_unadjusted
results$BH=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$Bonferroni=p.adjust(results$p_value_unadjusted, method="bonferroni")
results$p_value_unadjusted=NULL

results.aid1.mp=results

hd1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories", this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*z_donor_frequency", this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd4 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*z_winner_percent", this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd5 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*school_need_index", this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

results=data.frame(Hypothesis=integer(), p_value_unadjusted=integer())
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd1)$p.value[17]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd2)$p.value[21]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd4)$p.value[21]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd5)$p.value[20]




results$Hypothesis=c(
  "H1. Politicians will be more likely to allocate to schools that have already benefitted from more past aid projects and where donors have provided more categories of goods.",
  "H2. Treatment effect will be greater when politicians interact frequently with donors.",
  "H3. Treatment effect will be greater where the politician did not receive a high proportion of votes.",
  "H4. Treatment effect will be greater where schools are less needy."
  )

results$unadjusted=results$p_value_unadjusted
results$BH=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$bonferroni=p.adjust(results$p_value_unadjusted, method="bonferroni")
results$p_value_unadjusted=NULL

results.aid1.controls=results



hd1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*z_donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd4 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd5 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
results=data.frame(Hypothesis=integer(), p_value_unadjusted=integer())
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd1)$p.value[3]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd2)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd4)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd5)$p.value[7]

results$Hypothesis=c(
  "H1. Politicians will be more likely to allocate to schools that have already benefitted from more past aid projects and where donors have provided more categories of goods.",
  "H2. Treatment effect will be greater when politicians interact frequently with donors.",
  "H3. Treatment effect will be greater where the politician did not receive a high proportion of votes.",
  "H4. Treatment effect will be greater where schools are less needy."
  )


results$'Unadjusted Aid Projects'=results$p_value_unadjusted
results$'BH Aid Projects'=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$'Bonferroni Aid Projects'=p.adjust(results$p_value_unadjusted, method="bonferroni")
results$p_value_unadjusted=NULL

results.aid2=results


hd1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project", this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*z_donor_frequency", this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd4 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*z_winner_percent", this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hd5 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*school_need_index", this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

results=data.frame(Hypothesis=integer(), p_value_unadjusted=integer())
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd1)$p.value[17]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd2)$p.value[21]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd4)$p.value[21]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd5)$p.value[20]


results$Hypothesis=c(
  "H1. Politicians will be more likely to allocate to schools that have already benefitted from more past aid projects and where donors have provided more categories of goods.",
  "H2. Treatment effect will be greater when politicians interact frequently with donors.",
  "H3. Treatment effect will be greater where the politician did not receive a high proportion of votes.",
  "H4. Treatment effect will be greater where schools are less needy."
  )


results$unadjusted=results$p_value_unadjusted
results$BH=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$bonferroni=p.adjust(results$p_value_unadjusted, method="bonferroni")
results$p_value_unadjusted=NULL

results.aid2.controls=results


hd1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
hd2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*z_donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
hd4 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
hd5 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
results=data.frame(Hypothesis=integer(), p_value_unadjusted=integer())
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd1)$p.value[3]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd2)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd4)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd5)$p.value[7]

results$Hypothesis=c(
  "H1. Politicians will be more likely to allocate to schools that have already benefitted from more past aid projects and where donors have provided more categories of goods.",
  "H2. Treatment effect will be greater when politicians interact frequently with donors.",
  "H3. Treatment effect will be greater where the politician did not receive a high proportion of votes.",
  "H4. Treatment effect will be greater where schools are less needy."
  )

results$Unadjusted=results$p_value_unadjusted
results$BH=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$Bonferroni=p.adjust(results$p_value_unadjusted, method="bonferroni")
results$p_value_unadjusted=NULL

results.aid2.lc=results



hd1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
hd2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*z_donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
hd4 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
hd5 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
results=data.frame(Hypothesis=integer(), p_value_unadjusted=integer())
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd1)$p.value[3]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd2)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd4)$p.value[7]
results[nrow(results)+1,]$p_value_unadjusted=tidy(hd5)$p.value[7]

results$Hypothesis=c(
  "H1. Politicians will be more likely to allocate to schools that have already benefitted from more past aid projects and where donors have provided more categories of goods.",
  "H2. Treatment effect will be greater when politicians interact frequently with donors.",
  "H3. Treatment effect will be greater where the politician did not receive a high proportion of votes.",
  "H4. Treatment effect will be greater where schools are less needy."
  )

results$Unadjusted=results$p_value_unadjusted
results$BH=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$Bonferroni=p.adjust(results$p_value_unadjusted, method="bonferroni")
results$p_value_unadjusted=NULL

results.aid2.mp=results




xt=xtable(cbind(results.aid1, results.aid2[,c(2:4)]),  digits=4, label="tab_multiple_comparison_aid", caption="Multiple Comparison Adjustment, Foreign Aid Information", align=c("p{0.01\\textwidth}|",
               "p{0.3\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|"
               ))


print(xt, include.rownames=FALSE,  caption.placement = "top", hline.after=c(-1, 0))
print(xt, include.rownames=FALSE,  caption.placement = "top", hline.after=c(-1, 0), file="./Output/tab_multiple_comparison_aid.tex")



#political support hypotheses
this.controls=gsub(" \\+  winner_percent","", controls)

hc1 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hc2 = clogit(as.formula(paste("incumbentselected ~ information_votes*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


results=data.frame(Hypothesis="H1.  Politicians will be more likely to allocate to schools located in areas with higher support for the politicians in the last election.", p_value_unadjusted=tidy(hc1)$p.value[3])
results=rbind(results, data.frame(Hypothesis="H2. Politicians will be less likely to allocate to schools in areas with high need", p_value_unadjusted=tidy(hc2)$p.value[3]))

results$Unadjusted=results$p_value_unadjusted
results$BH=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$Bonferroni=round(p.adjust(results$p_value_unadjusted, method="bonferroni"),4)
results$p_value_unadjusted=NULL

results.votes=results


hc1 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
hc2 = clogit(as.formula(paste("incumbentselected ~ information_votes*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)


results=data.frame(Hypothesis="H1.  Politicians will be more likely to allocate to schools located in areas with higher support for the politicians in the last election.", p_value_unadjusted=tidy(hc1)$p.value[3])
results=rbind(results, data.frame(Hypothesis="H2. Politicians will be less likely to allocate to schools in areas with high need", p_value_unadjusted=tidy(hc2)$p.value[3]))

results$Unadjusted=results$p_value_unadjusted
results$BH=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$Bonferroni=round(p.adjust(results$p_value_unadjusted, method="bonferroni"),4)
results$p_value_unadjusted=NULL

results.votes.mp=results


hc1 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
hc2 = clogit(as.formula(paste("incumbentselected ~ information_votes*school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)


results=data.frame(Hypothesis="H1.  Politicians will be more likely to allocate to schools located in areas with higher support for the politicians in the last election.", p_value_unadjusted=tidy(hc1)$p.value[3])
results=rbind(results, data.frame(Hypothesis="H2. Politicians will be less likely to allocate to schools in areas with high need", p_value_unadjusted=tidy(hc2)$p.value[3]))

results$Unadjusted=results$p_value_unadjusted
results$BH=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$Bonferroni=round(p.adjust(results$p_value_unadjusted, method="bonferroni"),4)
results$p_value_unadjusted=NULL

results.votes.lc=results

hc1 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent",this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hc2 = clogit(as.formula(paste("incumbentselected ~ information_votes*school_need_index",this.controls," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


results=data.frame(Hypothesis="H1.  Politicians will be more likely to allocate to schools located in areas with higher support for the politicians in the last election.", p_value_unadjusted=tidy(hc1)$p.value[18])
results=rbind(results, data.frame(Hypothesis="H2. Politicians will be less likely to allocate to schools in areas with high need", p_value_unadjusted=tidy(hc2)$p.value[17]))

results$'Unadjusted with Controls'=results$p_value_unadjusted
results$'BH with Controls'=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$'Bonferroni with Controls'=round(p.adjust(results$p_value_unadjusted, method="bonferroni"),4)
results$p_value_unadjusted=NULL

results.votes.controls=results

hc1.trans = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*transparency_all + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
hc2.trans = clogit(as.formula(paste("incumbentselected ~ information_votes*school_need_index*transparency_all + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


results=data.frame(Hypothesis=integer(), p_value_unadjusted=integer())

model_id=0
for(m in list(hc1.trans, hc2.trans)){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var=c("z_winner_percent", "school_need_index")
  this.treat="information_votes"
  this.mediator="transparency_all"
  
  t=1
  k=1

  ate =  m$coefficients[paste0(this.treat, ":", this.var[model_id])]+
    m$coefficients[paste0(this.treat,  ":", this.var[model_id], ":", this.mediator)]*k
  
  ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var[model_id]), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.var[model_id], ":", this.mediator), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var[model_id]), paste0(this.treat,  ":", this.var[model_id], ":", this.mediator)])
          
    results[i,]$p_value_unadjusted=2*pt(q=abs(ate/ate_se), df=m$n-1, lower=FALSE)

}



results$Unadjusted_Tranparency=results$p_value_unadjusted
results$BH_Transparency=round(p.adjust(results$p_value_unadjusted, method="BH"),4)
results$Bonferroni_Transparency=round(p.adjust(results$p_value_unadjusted, method="bonferroni"),4)
results$p_value_unadjusted=NULL

results.votes.transparency=results



xt=xtable(cbind(results.votes, results.votes.controls[,2:4]),  digits=4, label="tab_multiple_comparison_votes", caption="Multiple Comparison Adjustment, Political Support Information", align=c(
               "p{0.01\\textwidth}|",
               "p{0.25\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|",
               "p{0.1\\textwidth}|"
               ))


print(xt, include.rownames=FALSE,  caption.placement = "top", hline.after=c(-1, 0))
print(xt, include.rownames=FALSE,  caption.placement = "top", hline.after=c(-1, 0), file="./Output/tab_multiple_comparison_votes.tex")


results.plot=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, model=NA)
i=0

#need
i=i+1
results.plot[i,]$term="Pooled"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.need[1,2]


i=i+1
results.plot[i,]$term="Pooled"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.need[1,3]

i=i+1
results.plot[i,]$term="Pooled"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.need[1,4]

i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.need.controls[1,2]

i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.need.controls[1,3]


i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.need.controls[1,4]

i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.need.mp[1,2]

i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.need.mp[1,3]

i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.need.mp[1,4]

i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.need.lc[1,2]

i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.need.lc[1,3]


i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.need.lc[1,4]

#aid

i=i+1
results.plot[i,]$term="Pooled \n(Aid Projects)"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.aid2[1,2]

i=i+1
results.plot[i,]$term="Pooled \n(Aid Projects)"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.aid2[1,3]


i=i+1
results.plot[i,]$term="Pooled \n(Aid Projects)"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.aid2[1,4]

i=i+1
results.plot[i,]$term="Pooled \n(Aid Types)"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.aid1[1,2]

i=i+1
results.plot[i,]$term="Pooled \n(Aid Types)"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.aid1[1,3]

i=i+1
results.plot[i,]$term="Pooled \n(Aid Types)"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.aid1[1,4]


i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.aid2.controls[1,2]

i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.aid2.controls[1,3]


i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.aid2.controls[1,4]


i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.aid2.mp[1,2]

i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.aid2.mp[1,3]

i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.aid2.mp[1,4]


i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.aid2.lc[1,2]

i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.aid2.lc[1,3]



i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.aid2.lc[1,4]

#votes

i=i+1
results.plot[i,]$term="Pooled"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.votes[1,2]

i=i+1
results.plot[i,]$term="Pooled"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.votes[1,3]

i=i+1
results.plot[i,]$term="Pooled"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.votes[1,4]

i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.votes.controls[1,2]

i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.votes.controls[1,3]


i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.votes.controls[1,4]

i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.votes.mp[1,2]

i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.votes.mp[1,3]


i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.votes.mp[1,4]

i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.votes.lc[1,2]

i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.votes.lc[1,3]

i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.votes.lc[1,4]

#aid 2

i=i+1
results.plot[i,]$term="Pooled"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.aid2[1,2]

i=i+1
results.plot[i,]$term="Pooled"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.aid2[1,3]

i=i+1
results.plot[i,]$term="Pooled"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.aid2[1,4]

i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.aid2.controls[1,2]

i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.aid2.controls[1,3]


i=i+1
results.plot[i,]$term="with Controls"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.aid2.controls[1,4]

i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.aid2.mp[1,2]

i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.aid2.mp[1,3]


i=i+1
results.plot[i,]$term="MPs"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.aid2.mp[1,4]

i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Unadjusted"
results.plot[i,]$estimate=results.aid2.lc[1,2]

i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Benjamini-Hochberg"
results.plot[i,]$estimate=results.aid2.lc[1,3]

i=i+1
results.plot[i,]$term="Councillors"
results.plot[i,]$model="Bonferroni"
results.plot[i,]$estimate=results.aid2.lc[1,4]


p1=dwplot(results.plot[1:12,],dodge_size = 0,
          dot_args = list(size = 2)
          )+
  theme_bw() + xlab("p-value") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(2, 0),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.2),
        legend.margin=margin(l = 0.03, r=0.1, t=0,b=0.03, unit='cm'),
        legend.title = element_blank(),
                text = element_text(size = 13)) +
        coord_cartesian(xlim=c(0, 1.0))+
  scale_color_manual(values=wes_palette(n=3, name="Moonrise2"))+
scale_x_continuous(breaks=c(0, .1, .25, .5,.75,1), labels=c("0", "0.1", "0.25", "0.5","0.75","1.0")) 

p2=dwplot(results.plot[13:27,],dodge_size = 0,
          dot_args = list(size = 2))+
  theme_bw() + xlab("p-value") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(2, 0),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.2),
        legend.margin=margin(l = 0.03, r=0.1, t=0,b=0.03, unit='cm'),
        legend.title = element_blank(),
        text = element_text(size = 13)
        ) +
        coord_cartesian(xlim=c(0, 1.0))+
  scale_color_manual(values=wes_palette(n=3, name="Moonrise2"))+
    scale_x_continuous(breaks=c(0, .1, .25, .5,.75,1), labels=c("0", "0.1", "0.25", "0.5","0.75","1.0")) 


p3=dwplot(results.plot[28:39,],dodge_size = 0,
          dot_args = list(size = 2))+
  theme_bw() + xlab("p-value") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(1.5, 0.01),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.2),
        legend.margin=margin(l = 0.03, r=0.1, t=0,b=0.03, unit='cm'),
        text = element_text(size = 13)
        ) +
        coord_cartesian(xlim=c(0, 1.0))+
  scale_color_manual(name="Multiple Comparison\n Correction", values=wes_palette(n=3, name="Moonrise2"))+
scale_x_continuous(breaks=c(0, .1, .25, .5,.75,1), labels=c("0", "0.1", "0.25", "0.5","0.75","1.0")) 



 grid.arrange (arrangeGrob(p1, top="H1: Need Information" ),arrangeGrob(p2,top="H2: Aid Information"),arrangeGrob(p3,top="H3: Voting Information"), ncol=2, nrow=2, widths = c(4,4) ,heights = c(4,4))
 
pdf("./Output/multiplecomparison_plot.pdf",width=7.5, height=6, family="Helvetica")
 grid.arrange (arrangeGrob(p1, top="H1: Need Information" ),arrangeGrob(p2,top="H2: Aid Information"),arrangeGrob(p3,top="H3: Voting Information"), ncol=2, nrow=2, widths = c(4,4) ,heights = c(4,4))
dev.off()





```



\subsection{Interaction Effect Plot (Figure 11, Tables S14, S15, S16)}
```{r distance_plot, message=FALSE, warning=FALSE, echo=FALSE, results='asis'}



results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, exp_ate=NA, ate_se=NA, ate.high=NA, ate.low=NA, exp_ate.high=NA, exp_ate.low=NA)



m1.pooled.distance = clogit(as.formula(paste("incumbentselected ~ information_aid*z_school_home_distance*z_past_aid_project+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m.aid.distance=m1.pooled.distance


q=quantile(all.surveys$z_school_home_distance, na.rm=T, probs=seq(.1, 0.9, 0.2))
xlab=c("10%", "30%","50%","70%", "90%")
ylimits=c(0.4, 1.6)

models <- rep(list(m1.pooled.distance), length(q))

model_id=0
i=0

for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_past_aid_project"
  this.treat="information_aid"
  this.mediator="z_school_home_distance"

  t=1
  
 k=q[model_id]

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  results[i,]$exp_ate.low=exp(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$exp_ate.high=exp(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$ate.low=(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$ate.high=(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)
  results[i,]$exp_ate=exp(results[i,]$ate)
  results[i,]$term=model_id

      
}
results=results[!is.na(results$ate),]

pd <- position_dodge(0.01) # move them .05 to the left and right

p1=ggplot(results, aes(x=term, y=exp_ate)) + 
    geom_errorbar(aes(ymin=exp_ate.low, ymax=exp_ate.high), colour="black", width=.1, position=pd) +
     geom_line() +
    geom_point(position=pd, size=3, shape=21) + # 21 is filled circle
  geom_hline(yintercept = 1, colour = "black", linetype = 2, size=0.4)+
     xlab("Distance from Home") +
    scale_y_continuous(breaks=seq(0,2, by=0.2)) +         # Set tick every 4
      coord_cartesian(ylim=ylimits)+
    theme_bw() +
    theme(legend.justification=c(1,0),
          legend.position=c(1,0))     +
      scale_x_continuous(breaks=c(1:nrow(results)), labels=xlab)




results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, exp_ate=NA, ate_se=NA, ate.high=NA, ate.low=NA, exp_ate.high=NA, exp_ate.low=NA)

m1.pooled.distance = clogit(as.formula(paste("incumbentselected ~ information_need*z_school_home_distance*school_need_index+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m.need.distance=m1.pooled.distance


models <- rep(list(m1.pooled.distance), length(q))

model_id=0
i=0

for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="school_need_index"
  this.treat="information_need"
  this.mediator="z_school_home_distance"

  t=1
  
 k=q[model_id]

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  results[i,]$exp_ate.low=exp(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$exp_ate.high=exp(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$ate.low=(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$ate.high=(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)
  results[i,]$exp_ate=exp(results[i,]$ate)
  results[i,]$term=model_id

      
}
results=results[!is.na(results$ate),]

pd <- position_dodge(0.01) # move them .05 to the left and right

p2=ggplot(results, aes(x=term, y=exp_ate)) + 
    geom_errorbar(aes(ymin=exp_ate.low, ymax=exp_ate.high), colour="black", width=.1, position=pd) +
     geom_line() +
    geom_point(position=pd, size=3, shape=21) + # 21 is filled circle
  geom_hline(yintercept = 1, colour = "black", linetype = 2, size=0.4)+
     xlab("Distance from Home") +
     scale_y_continuous(breaks=seq(0,2, by=0.2)) +         # Set tick every 4
      coord_cartesian(ylim=ylimits)+       # Set tick every 4
    theme_bw() +
    theme(legend.justification=c(1,0),
          legend.position=c(1,0))   +  
  scale_x_continuous(breaks=c(1:nrow(results)), labels=xlab)





results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, exp_ate=NA, ate_se=NA, ate.high=NA, ate.low=NA, exp_ate.high=NA, exp_ate.low=NA)

m1.pooled.distance = clogit(as.formula(paste("incumbentselected ~ information_votes*z_school_home_distance*z_winner_percent+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m.votes.distance=m1.pooled.distance

models <- rep(list(m1.pooled.distance), length(q))

model_id=0
i=0

for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_winner_percent"
  this.treat="information_votes"
  this.mediator="z_school_home_distance"

  t=1
  
 k=q[model_id]

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  results[i,]$exp_ate.low=exp(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$exp_ate.high=exp(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$ate.low=(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$ate.high=(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)
  results[i,]$exp_ate=exp(results[i,]$ate)
  results[i,]$term=model_id

      
}
results=results[!is.na(results$ate),]

pd <- position_dodge(0.01) # move them .05 to the left and right

p3=ggplot(results, aes(x=term, y=exp_ate)) + 
    geom_errorbar(aes(ymin=exp_ate.low, ymax=exp_ate.high), colour="black", width=.1, position=pd) +
     geom_line() +
    geom_point(position=pd, size=3, shape=21) + # 21 is filled circle
  geom_hline(yintercept = 1, colour = "black", linetype = 2, size=0.4)+
     xlab("Distance from Home") +
     scale_y_continuous(breaks=seq(0,2, by=0.2)) +         # Set tick every 4
      coord_cartesian(ylim=ylimits)+       # Set tick every 4
    theme_bw() +
    theme(legend.justification=c(1,0),
          legend.position=c(1,0))   +  
  scale_x_continuous(breaks=c(1:nrow(results)), labels=xlab)

results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, exp_ate=NA, ate_se=NA, ate.high=NA, ate.low=NA, exp_ate.high=NA, exp_ate.low=NA)



m1.pooled.distance = clogit(as.formula(paste("incumbentselected ~ information_aid*z_pop_per_hectacre*z_past_aid_project+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m.aid.density=m1.pooled.distance

q=quantile(all.surveys$z_pop_per_hectacre, na.rm=T, probs=seq(0.1, 0.9, 0.2))

models <- rep(list(m1.pooled.distance), length(q))

model_id=0
i=0

for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_past_aid_project"
  this.treat="information_aid"
  this.mediator="z_pop_per_hectacre"

  t=1
  
 k=q[model_id]

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  results[i,]$exp_ate.low=exp(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$exp_ate.high=exp(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$ate.low=(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$ate.high=(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)
  results[i,]$exp_ate=exp(results[i,]$ate)
  results[i,]$term=model_id

      
}
results=results[!is.na(results$ate),]

pd <- position_dodge(0.01) # move them .05 to the left and right

p4=ggplot(results, aes(x=term, y=exp_ate)) + 
    geom_errorbar(aes(ymin=exp_ate.low, ymax=exp_ate.high), colour="black", width=.1, position=pd) +
     geom_line() +
    geom_point(position=pd, size=3, shape=21) + # 21 is filled circle
  geom_hline(yintercept = 1, colour = "black", linetype = 2, size=0.4)+
     xlab("Population Density") +
     scale_y_continuous(breaks=seq(0,2, by=0.2)) +         # Set tick every 4
      coord_cartesian(ylim=ylimits)+       # Set tick every 4
    theme_bw() +
    theme(legend.justification=c(1,0),
          legend.position=c(1,0))    + 
  scale_x_continuous(breaks=c(1:nrow(results)), labels=xlab)




results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, exp_ate=NA, ate_se=NA, ate.high=NA, ate.low=NA, exp_ate.high=NA, exp_ate.low=NA)

m1.pooled.distance = clogit(as.formula(paste("incumbentselected ~ information_need*z_pop_per_hectacre*school_need_index+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m.need.density=m1.pooled.distance

models <- rep(list(m1.pooled.distance), length(q))

model_id=0
i=0

for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="school_need_index"
  this.treat="information_need"
  this.mediator="z_pop_per_hectacre"

  t=1
  
 k=q[model_id]

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  results[i,]$exp_ate.low=exp(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$exp_ate.high=exp(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$ate.low=(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$ate.high=(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)
  results[i,]$exp_ate=exp(results[i,]$ate)
  results[i,]$term=model_id

      
}
results=results[!is.na(results$ate),]

pd <- position_dodge(0.01) # move them .05 to the left and right

p5=ggplot(results, aes(x=term, y=exp_ate)) + 
    geom_errorbar(aes(ymin=exp_ate.low, ymax=exp_ate.high), colour="black", width=.1, position=pd) +
     geom_line() +
    geom_point(position=pd, size=3, shape=21) + # 21 is filled circle
  geom_hline(yintercept = 1, colour = "black", linetype = 2, size=0.4)+
     xlab("Population Density") +
     scale_y_continuous(breaks=seq(0,2, by=0.2)) +         # Set tick every 4
      coord_cartesian(ylim=ylimits)+       # Set tick every 4
    theme_bw() +
    theme(legend.justification=c(1,0),
          legend.position=c(1,0))+     
  scale_x_continuous(breaks=c(1:nrow(results)), labels=xlab)


results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, exp_ate=NA, ate_se=NA, ate.high=NA, ate.low=NA, exp_ate.high=NA, exp_ate.low=NA)

m1.pooled.distance = clogit(as.formula(paste("incumbentselected ~ information_votes*z_pop_per_hectacre*z_winner_percent+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m.votes.density=m1.pooled.distance

models <- rep(list(m1.pooled.distance), length(q))

model_id=0
i=0

for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_winner_percent"
  this.treat="information_votes"
  this.mediator="z_pop_per_hectacre"

  t=1
  
 k=q[model_id]

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  results[i,]$exp_ate.low=exp(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$exp_ate.high=exp(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$ate.low=(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$ate.high=(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)
  results[i,]$exp_ate=exp(results[i,]$ate)
  results[i,]$term=model_id

      
}
results=results[!is.na(results$ate),]

pd <- position_dodge(0.01) # move them .05 to the left and right

p6=ggplot(results, aes(x=term, y=exp_ate)) + 
    geom_errorbar(aes(ymin=exp_ate.low, ymax=exp_ate.high), colour="black", width=.1, position=pd) +
     geom_line() +
    geom_point(position=pd, size=3, shape=21) + # 21 is filled circle
  geom_hline(yintercept = 1, colour = "black", linetype = 2, size=0.4)+
     xlab("Population Density") +
     scale_y_continuous(breaks=seq(0,2, by=0.2)) +         # Set tick every 4
      coord_cartesian(ylim=ylimits)+       # Set tick every 4
    theme_bw() +
    theme(legend.justification=c(1,0),
          legend.position=c(1,0))+     
  scale_x_continuous(breaks=c(1:nrow(results)), labels=xlab)


#winner percent

results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, exp_ate=NA, ate_se=NA, ate.high=NA, ate.low=NA, exp_ate.high=NA, exp_ate.low=NA)

m1.pooled.distance = clogit(as.formula(paste("incumbentselected ~ information_aid*z_winner_percent*z_past_aid_project+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

m.aid.votes=m1.pooled.distance

q=quantile(all.surveys$winner_percent, na.rm=T, probs=seq(0.1, 0.9, 0.2))

models <- rep(list(m1.pooled.distance), length(q))

model_id=0
i=0

for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="z_past_aid_project"
  this.treat="information_aid"
  this.mediator="z_winner_percent"

  t=1
  
 k=q[model_id]

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  results[i,]$exp_ate.low=exp(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$exp_ate.high=exp(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$ate.low=(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$ate.high=(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)
  results[i,]$exp_ate=exp(results[i,]$ate)
  results[i,]$term=model_id

      
}
results=results[!is.na(results$ate),]

pd <- position_dodge(0.01) # move them .05 to the left and right

p7=ggplot(results, aes(x=term, y=exp_ate)) + 
    geom_errorbar(aes(ymin=exp_ate.low, ymax=exp_ate.high), colour="black", width=.1, position=pd) +
     geom_line() +
    geom_point(position=pd, size=3, shape=21) + # 21 is filled circle
  geom_hline(yintercept = 1, colour = "black", linetype = 2, size=0.4)+
     xlab("Percent Votes") +
     scale_y_continuous(breaks=seq(0,2, by=0.2)) +         # Set tick every 4
      coord_cartesian(ylim=ylimits)+       # Set tick every 4
    theme_bw() +
    theme(legend.justification=c(1,0),
          legend.position=c(1,0))    + 
  scale_x_continuous(breaks=c(1:nrow(results)), labels=xlab)




results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, conf.low=NA, conf.high=NA, model=NA, predictor=NA, ate=NA, exp_ate=NA, ate_se=NA, ate.high=NA, ate.low=NA, exp_ate.high=NA, exp_ate.low=NA)

m1.pooled.distance = clogit(as.formula(paste("incumbentselected ~ information_need*z_winner_percent*school_need_index+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m.need.votes=m1.pooled.distance

models <- rep(list(m1.pooled.distance), length(q))

model_id=0
i=0

for(m in models){
  
  i=nrow(results)+1
  model_id=model_id+1
  this.var="school_need_index"
  this.treat="information_need"
  this.mediator="z_winner_percent"

  t=1
  
 k=q[model_id]

  
  results[i,]$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.treat, ":", this.var)]*t+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*t*k+
    m$coefficients[paste0(this.mediator, ":", this.var)]*k
  
  results[i,]$ate =  m$coefficients[paste0(this.treat, ":", this.var)]+
    m$coefficients[paste0(this.treat,  ":", this.mediator, ":", this.var)]*k
  
  results[i,]$ate_se =  sqrt(t^2*coef(summary(m))[paste0(this.treat, ":", this.var), "robust se"]^2 +
                         k^2*t^2*coef(summary(m))[paste0(this.treat,  ":", this.mediator, ":", this.var), "robust se"]^2 +
                           2*k*t^2*vcov(m)[paste0(this.treat, ":", this.var), paste0(this.treat,  ":", this.mediator, ":", this.var)])
          
  results[i,]$exp_ate.low=exp(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$exp_ate.high=exp(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$ate.low=(results[i,]$ate-qt(0.975,df=m$n-1)*results[i,]$ate_se)
  results[i,]$ate.high=(results[i,]$ate +qt(0.975,df=m$n-1)*results[i,]$ate_se)
  
  results[i,]$p.value=2*pt(q=abs(results[i,]$ate/results[i,]$ate_se), df=m$n-1, lower=FALSE)
  results[i,]$exp_ate=exp(results[i,]$ate)
  results[i,]$term=model_id

      
}
results=results[!is.na(results$ate),]

pd <- position_dodge(0.01) # move them .05 to the left and right

p8=ggplot(results, aes(x=term, y=exp_ate)) + 
    geom_errorbar(aes(ymin=exp_ate.low, ymax=exp_ate.high), colour="black", width=.1, position=pd) +
     geom_line() +
    geom_point(position=pd, size=3, shape=21) + # 21 is filled circle
  geom_hline(yintercept = 1, colour = "black", linetype = 2, size=0.4)+
     xlab("Percent Votes") +
     scale_y_continuous(breaks=seq(0,2, by=0.2)) +         # Set tick every 4
      coord_cartesian(ylim=ylimits)+       # Set tick every 4
    theme_bw() +
    theme(legend.justification=c(1,0),
          legend.position=c(1,0))+     
  scale_x_continuous(breaks=c(1:nrow(results)), labels=xlab)


p1=p1+coord_cartesian(ylim=c(0.2, 1.5))+ylab("") 
p4=p4+coord_cartesian(ylim=c(0.2, 1.5))+ylab("") 
p7=p7+coord_cartesian(ylim=c(0.2, 1.5))+ylab("") 

p2=p2+coord_cartesian(ylim=c(0.8, 1.4))+ylab("Treatment Effect") 
p5=p5+coord_cartesian(ylim=c(0.8, 1.4))+ylab("Treatment Effect") 
p8=p8+coord_cartesian(ylim=c(0.8, 1.4))+ylab("Treatment Effect") 

p3=p3+coord_cartesian(ylim=c(0.6, 1.6))+ylab("") 
p6=p6+coord_cartesian(ylim=c(0.6, 1.6))+ylab("") 





 grid.arrange (arrangeGrob(p2, top="A: Need Information" ),arrangeGrob(p1,top="B: Aid Information"),arrangeGrob(p3,top="C: Voting Information"),p5,p4,p6,p8, p7, ncol=3, nrow=3, widths = c(4,4,4) ,heights = c(4,4,4))
 
pdf("./Output/het_plot.pdf",width=6, height=6, family="Helvetica")
grid.arrange (arrangeGrob(p2, top="A: Need Information" ),arrangeGrob(p1,top="B: Aid Information"),arrangeGrob(p3,top="C: Voting Information"),p5,p4,p6,p8, p7, ncol=3, nrow=3, widths = c(4,4,4) ,heights = c(4,4,4))
 
 
dev.off()


sg=capture.output(stargazer(m.need.distance, m.need.density,m.need.votes, type = "latex", 
          out=paste("./Output/tab_het_need.tex", sep=""), 
 column.labels = c("\\makecell{Distance \\\\Interactions}","\\makecell{Density \\\\Interactions}", "\\makecell{Voting \\\\Interactions}"),
 model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 11 (Need Interactions)",
          order=c("^information_need:z_school_home_distance:school_need_index$",
                  "^information_need:z_winner_percent:school_need_index$",
                  "^information_need:z_pop_per_hectacre:school_need_index$",
                  "^information_need:school_need_index$",
                  "^information_need:z_school_home_distance$",
                  "^information_need:z_pop_per_hectacre$",
                  "^information_need:z_winner_percent$",
                  "^z_school_home_distance:school_need_index$",
                  "^z_pop_per_hectacre:school_need_index$",
                  "^z_winner_percent:school_need_index$",
                  "information_need", 
                  "^school_need_index$", 
                  "^z_winner_percent$", 
                  "^z_school_home_distance$",
                  "^z_pop_per_hectacre$"),
          keep="*",
          covariate.labels = c(labelme("information_need:z_school_home_distance:school_need_index"),
                  labelme("information_need:z_winner_percent:school_need_index"),
                  labelme("information_need:z_pop_per_hectacre:school_need_index"),
                  labelme("information_need:school_need_index"),
                  labelme("information_need:z_school_home_distance"),
                  labelme("information_need:z_pop_per_hectacre"),
                  labelme("information_need:z_winner_percent"),
                  labelme("z_school_home_distance:school_need_index"),
                  labelme("z_pop_per_hectacre:school_need_index"),
                  labelme("winner_percent:school_need_index"),
                  labelme("information_need"), 
                  labelme("school_need_index"), 
                  labelme("winner_percent"), 
                  labelme("z_school_home_distance"),
                  labelme("z_pop_per_hectacre")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_het_need", sep=""),
          table.placement = "H"
          
))


stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_het_need.tex")



sg=capture.output(stargazer(m.aid.distance, m.aid.density,m.aid.votes, type = "latex", 
          out=paste("./Output/tab_het_aid.tex", sep=""), 
          column.labels = c("\\makecell{Distance \\\\Interactions}","\\makecell{Density \\\\Interactions}", "\\makecell{Voting \\\\Interactions}"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 11 (Aid Interactions)",
          order=c("^information_aid:z_school_home_distance:z_past_aid_project$",
                  "^information_aid:z_winner_percent:z_past_aid_project$",
                  "^information_aid:z_pop_per_hectacre:z_past_aid_project$",
                  "^information_aid:z_past_aid_project$",
                  "^information_aid:z_school_home_distance$",
                  "^information_aid:z_pop_per_hectacre$",
                  "^information_aid:z_winner_percent$",
                  "^z_school_home_distance:z_past_aid_project$",
                  "^z_pop_per_hectacre:z_past_aid_project$",
                  "^z_winner_percent:z_past_aid_project$",
                  "information_aid", 
                  "^z_past_aid_project$", 
                  "^z_winner_percent$", 
                  "^z_school_home_distance$",
                  "^z_pop_per_hectacre$"),
          keep="*",
          covariate.labels = c(labelme("information_aid:z_school_home_distance:z_past_aid_project"),
                  labelme("information_aid:z_winner_percent:z_past_aid_project"),
                  labelme("information_aid:z_pop_per_hectacre:z_past_aid_project"),
                  labelme("information_aid:z_past_aid_project"),
                  labelme("information_aid:z_school_home_distance"),
                  labelme("information_aid:z_pop_per_hectacre"),
                  labelme("information_aid:z_winner_percent"),
                  labelme("z_school_home_distance:z_past_aid_project"),
                  labelme("z_pop_per_hectacre:z_past_aid_project"),
                  labelme("winner_percent:z_past_aid_project"),
                  labelme("information_aid"), 
                  labelme("past_aid_project"), 
                  labelme("winner_percent"), 
                  labelme("z_school_home_distance"),
                  labelme("z_pop_per_hectacre")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_het_aid", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_het_aid.tex")



sg=capture.output(stargazer(m.votes.distance, m.votes.density, type = "latex", 
          out=paste("./Output/tab_het_votes.tex", sep=""), 
          column.labels = c("\\makecell{Distance \\\\Interactions}","\\makecell{Density \\\\Interactions}"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Main Text Figure 11 (Voting Interactions)",
          order=c("^information_votes:z_school_home_distance:z_winner_percent$",
                  "^information_votes:z_pop_per_hectacre:z_winner_percent$",
                  "^information_votes:z_winner_percent$",
                  "^information_votes:z_school_home_distance$",
                  "^information_votes:z_pop_per_hectacre$",
                  "^z_school_home_distance:z_winner_percent$",
                  "^z_pop_per_hectacre:z_winner_percent$",
                  "information_votes", 
                  "^z_winner_percent$", 
                  "^z_school_home_distance$",
                  "^z_pop_per_hectacre$"),
          keep="*",
          covariate.labels = c(labelme("information_votes:school_home_distance:winner_percent"),
                  labelme("information_votes:z_pop_per_hectacre:winner_percent"),
                  labelme("information_votes:z_winner_percent"),
                  labelme("information_votes:school_home_distance"),
                  labelme("information_votes:z_pop_per_hectacre"),
                  labelme("school_home_distance:z_winner_percent"),
                  labelme("z_pop_per_hectacre:z_winner_percent"),
                  labelme("information_votes"), 
                  labelme("winner_percent"), 
                  labelme("school_home_distance"),
                  labelme("z_pop_per_hectacre")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_het_votes", sep=""),
          table.placement = "H"
          
))
stargazer_print(sg, "\\multicolumn{3}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_het_votes.tex")




```


\subsection{Interaction of Information Treatments with Transparency Treatments (Tables S26, S27, S28)}
\begin{landscape}

```{r transparency treatments interactions, message=FALSE, warning=FALSE, results='asis', echo=FALSE}



h.trans_any = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*transparency_all +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)



h.trans_donor = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*transparency_donor +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)



h.trans_radio =  clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*transparency_radio +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)


h.trans_all=  clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*transparency_radio*transparency_donor +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)





sg=capture.output(stargazer(h.trans_any, h.trans_donor, h.trans_radio, h.trans_all, type = "latex", 
          out=paste("./Output/tab_aid_trans_interactions.tex", sep=""), 
          column.labels = c("\\makecell{Any \\\\Treatment}","\\makecell{Donor \\\\Treatment}", "\\makecell{Radio \\\\Treatment}", "\\makecell{All \\\\Treatments}"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interaction of Aid Information Treatment with Transparency Treatments",
          order=c("^z_past_aid_project$","^information_aid:z_past_aid_project$","^z_past_aid_project:transparency_all$","^information_aid:z_past_aid_project:transparency_all$", 
                  "^z_past_aid_project:transparency_donor$", "^information_aid:z_past_aid_project:transparency_donor$",
                  "^z_past_aid_project:transparency_radio$", "^information_aid:z_past_aid_project:transparency_radio$", "^z_past_aid_project:transparency_radio:transparency_donor$", "^information_aid:z_past_aid_project:transparency_radio:transparency_donor$"),
          
           keep=c("^z_past_aid_project$","^information_aid:z_past_aid_project$","^z_past_aid_project:transparency_all$","^information_aid:z_past_aid_project:transparency_all$", 
                  "^z_past_aid_project:transparency_donor$", "^information_aid:z_past_aid_project:transparency_donor$",
                  "^z_past_aid_project:transparency_radio$", "^information_aid:z_past_aid_project:transparency_radio$", "^z_past_aid_project:transparency_radio:transparency_donor$", "^information_aid:z_past_aid_project:transparency_radio:transparency_donor$"),
          covariate.labels = c(labelme("past_aid_project"),labelme("information_aid:z_past_aid_project"),labelme("past_aid_project:transparency_all"),labelme("information_aid:z_past_aid_project:transparency_all"), labelme("past_aid_project:transparency_donor"), labelme("past_aid_project:information_aid:transparency_donor"), labelme("past_aid_project:transparency_radio"), labelme("information_aid:z_past_aid_project:transparency_radio"), labelme("past_aid_project:transparency_radio:transparency_donor"), labelme("information_aid:z_past_aid_project:transparency_radio:transparency_donor")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_aid_trans_interactions", sep=""),
          table.placement = "H"
))

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_aid_trans_interactions.tex")




h.trans_any = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*transparency_all +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)



h.trans_donor = clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*transparency_donor +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)



h.trans_radio =  clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*transparency_radio +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)


h.trans_all=  clogit(as.formula(paste("incumbentselected ~ information_aid*z_number_aid_categories*transparency_radio*transparency_donor +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)





sg=capture.output(stargazer(h.trans_any, h.trans_donor, h.trans_radio, h.trans_all, type = "latex", 
          out=paste("./Output/tab_aid2_trans_interactions.tex", sep=""), 
          column.labels = c("\\makecell{Any \\\\Treatment}","\\makecell{Donor \\\\Treatment}", "\\makecell{Radio \\\\Treatment}", "\\makecell{All \\\\Treatments}"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interaction of Aid Information Treatment with Transparency Treatments",
          order=c("^z_number_aid_categories$","^information_aid:z_number_aid_categories$","^z_number_aid_categories:transparency_all$","^information_aid:z_number_aid_categories:transparency_all$", 
                  "^z_number_aid_categories:transparency_donor$", "^information_aid:z_number_aid_categories:transparency_donor$",
                  "^z_number_aid_categories:transparency_radio$", "^information_aid:z_number_aid_categories:transparency_radio$", "^z_number_aid_categories:transparency_radio:transparency_donor$", "^information_aid:z_number_aid_categories:transparency_radio:transparency_donor$"),
          
           keep=c("^z_number_aid_categories$","^information_aid:z_number_aid_categories$","^z_number_aid_categories:transparency_all$","^information_aid:z_number_aid_categories:transparency_all$", 
                  "^z_number_aid_categories:transparency_donor$", "^information_aid:z_number_aid_categories:transparency_donor$",
                  "^z_number_aid_categories:transparency_radio$", "^information_aid:z_number_aid_categories:transparency_radio$", "^z_number_aid_categories:transparency_radio:transparency_donor$", "^information_aid:z_number_aid_categories:transparency_radio:transparency_donor$"),
          covariate.labels = c(labelme("number_aid_categories"),labelme("information_aid:z_number_aid_categories"),labelme("number_aid_categories:transparency_all"),labelme("information_aid:z_number_aid_categories:transparency_all"), labelme("number_aid_categories:transparency_donor"), labelme("number_aid_categories:information_aid:transparency_donor"), labelme("number_aid_categories:transparency_radio"), labelme("information_aid:z_number_aid_categories:transparency_radio"), labelme("number_aid_categories:transparency_radio:transparency_donor"), labelme("information_aid:z_number_aid_categories:transparency_radio:transparency_donor")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_aid2_trans_interactions", sep=""),
          table.placement = "H"
))

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_aid2_trans_interactions.tex")





h.trans_any = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*transparency_all +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)



h.trans_donor = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*transparency_donor +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)



h.trans_radio =  clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*transparency_radio +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)


h.trans_all=  clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*transparency_radio*transparency_donor +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)





sg=capture.output(stargazer(h.trans_any, h.trans_donor, h.trans_radio, h.trans_all, type = "latex", 
          out=paste("./Output/tab_need_trans_interactions.tex", sep=""), 
          column.labels = c("\\makecell{Any \\\\Treatment}","\\makecell{Donor \\\\Treatment}", "\\makecell{Radio \\\\Treatment}", "\\makecell{All \\\\Treatments}"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interaction of Need Information Treatment with Transparency Treatments",
          order=c("^school_need_index$","^information_need:school_need_index$","^school_need_index:transparency_all$","^information_need:school_need_index:transparency_all$", 
                  "^school_need_index:transparency_donor$", "^information_need:school_need_index:transparency_donor$",
                  "^school_need_index:transparency_radio$", "^information_need:school_need_index:transparency_radio$", "^school_need_index:transparency_radio:transparency_donor$", "^information_need:school_need_index:transparency_radio:transparency_donor$"),
          
           keep=c("^school_need_index$","^information_need:school_need_index$","^school_need_index:transparency_all$","^information_need:school_need_index:transparency_all$", 
                  "^school_need_index:transparency_donor$", "^information_need:school_need_index:transparency_donor$",
                  "^school_need_index:transparency_radio$", "^information_need:school_need_index:transparency_radio$", "^school_need_index:transparency_radio:transparency_donor$", "^information_need:school_need_index:transparency_radio:transparency_donor$"),
          covariate.labels = c(labelme("school_need_index"),labelme("information_need:school_need_index"),labelme("school_need_index:transparency_all"),labelme("information_need:school_need_index:transparency_all"), labelme("school_need_index:transparency_donor"), labelme("school_need_index:information_need:transparency_donor"), labelme("school_need_index:transparency_radio"), labelme("information_need:school_need_index:transparency_radio"), labelme("school_need_index:transparency_radio:transparency_donor"), labelme("information_need:school_need_index:transparency_radio:transparency_donor")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_need_trans_interactions", sep=""),
          table.placement = "H"
))

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_need_trans_interactions.tex")






h.trans_any = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*transparency_all +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)



h.trans_donor = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*transparency_donor +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)



h.trans_radio =  clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*transparency_radio +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)


h.trans_all=  clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*transparency_radio*transparency_donor +
                                 strata(map_id) + 
                                 cluster(resp_id)")), method="efron", all.surveys)





sg=capture.output(stargazer(h.trans_any, h.trans_donor, h.trans_radio, h.trans_all, type = "latex", 
          out=paste("./Output/tab_votes_trans_interactions.tex", sep=""), 
          column.labels = c("\\makecell{Any \\\\Treatment}","\\makecell{Donor \\\\Treatment}", "\\makecell{Radio \\\\Treatment}", "\\makecell{All \\\\Treatments}"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Interaction of Voting Information Treatment with Transparency Treatments",
          order=c("^z_winner_percent$","^information_votes:z_winner_percent$","^z_winner_percent:transparency_all$","^information_votes:z_winner_percent:transparency_all$", 
                  "^z_winner_percent:transparency_donor$", "^information_votes:z_winner_percent:transparency_donor$",
                  "^z_winner_percent:transparency_radio$", "^information_votes:z_winner_percent:transparency_radio$", "^z_winner_percent:transparency_radio:transparency_donor$", "^information_votes:z_winner_percent:transparency_radio:transparency_donor$"),
          
           keep=c("^z_winner_percent$","^information_votes:z_winner_percent$","^z_winner_percent:transparency_all$","^information_votes:z_winner_percent:transparency_all$", 
                  "^z_winner_percent:transparency_donor$", "^information_votes:z_winner_percent:transparency_donor$",
                  "^z_winner_percent:transparency_radio$", "^information_votes:z_winner_percent:transparency_radio$", "^z_winner_percent:transparency_radio:transparency_donor$", "^information_votes:z_winner_percent:transparency_radio:transparency_donor$"),
          covariate.labels = c(labelme("winner_percent"),labelme("information_votes:z_winner_percent"),labelme("winner_percent:transparency_all"),labelme("information_votes:z_winner_percent:transparency_all"), labelme("winner_percent:transparency_donor"), labelme("winner_percent:information_votes:transparency_donor"), labelme("winner_percent:transparency_radio"), labelme("information_votes:z_winner_percent:transparency_radio"), labelme("winner_percent:transparency_radio:transparency_donor"), labelme("information_votes:z_winner_percent:transparency_radio:transparency_donor")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_votes_trans_interactions", sep=""),
          table.placement = "H"
))

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_votes_trans_interactions.tex")



```

\end{landscape}



\section{Politician Knowledge and Updating}

\subsection{Correlates of Politician Knowledge (Table S34)}

```{r quiz_estimates, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

quiz.df=read.csv("./data/quiz_with_covariates.csv")
#first separate into question type
quiz.school=quiz.df[quiz.df$question_id %in% c(1,2,6,4,5),]
quiz.votes=quiz.df[quiz.df$question_id %in% c(3,7),]

#calculate the proportion of correct answers for each school
quiz.df.ag=aggregate(quiz.df$correct, by=list(quiz.df$school_id), mean)
quiz.df$correct=quiz.df.ag[match(quiz.df$school_id, quiz.df.ag$Group.1), "x"]
quiz.df=quiz.df[!duplicated(quiz.df$school_id),]

quiz.school.ag=aggregate(quiz.school$correct, by=list(quiz.school$school_id), mean)
quiz.school$correct=quiz.school.ag[match(quiz.school$school_id, quiz.school.ag$Group.1), "x"]
quiz.school=quiz.school[!duplicated(quiz.school$school_id),]

quiz.votes.ag=aggregate(quiz.votes$correct, by=list(quiz.votes$school_id), mean)
quiz.votes$correct=quiz.votes.ag[match(quiz.votes$school_id, quiz.votes.ag$Group.1), "x"]
quiz.votes=quiz.votes[!duplicated(quiz.votes$school_id),]

this.controls="z_school_home_distance + z_ps_winner_percent +  z_pop_per_hectacre + school_need_index + z_school_enrollment_total +  z_school_classrooms_permanent + z_poverty_proportion "

m1=felm(as.formula(paste("correct~ ", this.controls, " |resp_id  |0|0")), data=quiz.df)
m2=felm(as.formula(paste("correct~ ", this.controls, " |resp_id |0|0")), data=quiz.school)
m3=felm(as.formula(paste("correct~ ", this.controls, " |resp_id  |0|0")), data=quiz.votes)


sg=capture.output(stargazer(m1, m2, m3, type = "latex", 
          out=paste("./Output/tab_knowledge.tex", sep=""), 
          column.labels = c("All Questions","School Questions",  "Voting Questions"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Correlates of School Knowledge",
           no.space=TRUE,
          label=paste("tab:knowledge", sep=""),
          table.placement = "H",
           covariate.labels = c(labelme("school_home_distance"), labelme("winner_percent"), labelme("pop_per_hectacre"), labelme("school_need_index"), "School Enrollment", "Number of Permanent Classrooms", labelme("poverty_proportion"))))
          

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the results of a linear fixed-effect regression of school covariates on the proportion of correct answers about each school included in the post-experiment quiz. The outcome variable is the share of correct questions about each school. }", "tab_knowledge.tex")


```


\subsection{Summary of Quiz Answers (Figure 3 and Figure S14)}
```{r quiz_summary, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

c.byresp <- c.survey[!duplicated(c.survey[,c("ps_ward_id")]),]
mp.byresp <- mp.survey[!duplicated(mp.survey[,c("constituencyid")]),]
all.byresp=rbind.fill(c.byresp, mp.byresp)

#first create data based on expected number of correct answers under random guessing baseline
random.df=data.frame(varmean=NA, group=NA, sd=NA, upper=NA, lower=NA)
random.df[1,]$varmean=1/4*100
random.df[1,]$sd=0
random.df[1,]$upper=random.df[1,]$varmean + 1.96*random.df[1,]$sd
random.df[1,]$lower=random.df[1,]$varmean - 1.96*random.df[1,]$sd
random.df[1,]$group="Which school has \nthe least classrooms?"
random.df[2,]$varmean=1/4*100
random.df[2,]$sd=0
random.df[2,]$upper=random.df[2,]$varmean + 1.96*random.df[2,]$sd
random.df[2,]$lower=random.df[2,]$varmean - 1.96*random.df[2,]$sd
random.df[2,]$group="Which school has \nthe most students?"
random.df[3,]$varmean=1/7*100
random.df[3,]$sd=0
random.df[3,]$upper=random.df[3,]$varmean + 1.96*random.df[3,]$sd
random.df[3,]$lower=random.df[3,]$varmean - 1.96*random.df[3,]$sd
random.df[3,]$group="How many are enrolled in \nthis school?"
random.df[4,]$varmean=1/4*100
random.df[4,]$sd=0
random.df[4,]$upper=random.df[3,]$varmean + 1.96*random.df[3,]$sd
random.df[4,]$lower=random.df[3,]$varmean - 1.96*random.df[3,]$sd
random.df[4,]$group="In which school did you \nreceived lowest percent votes?"
random.df[5,]$varmean=1/7*100
random.df[5,]$sd=0
random.df[5,]$upper=random.df[3,]$varmean + 1.96*random.df[3,]$sd
random.df[5,]$lower=random.df[3,]$varmean - 1.96*random.df[3,]$sd
random.df[5,]$group="What were the \npercent votes in this school?"
random.df[6,]$varmean=1/4*100
random.df[6,]$sd=sd(c.byresp$test_most_projects, na.rm=TRUE)*100
random.df[6,]$upper=random.df[3,]$varmean + 1.96*random.df[3,]$sd
random.df[6,]$lower=random.df[3,]$varmean - 1.96*random.df[3,]$sd
random.df[6,]$group="Which school has the most\n donor projects?"
random.df[7,]$varmean=0
random.df[7,]$sd=0
random.df[7,]$upper=random.df[3,]$varmean + 1.96*random.df[3,]$sd
random.df[7,]$lower=random.df[3,]$varmean - 1.96*random.df[3,]$sd
random.df[7,]$group="What are the name(s) \nof the donor(s) at this school?"


random.df$group2=factor(random.df$group, 
                   levels=names(sort(table(random.df$group), 
                                     decreasing=FALSE)))


all.byresp$all_questions_count=(all.byresp$test_least_classes+all.byresp$test_most_enrollment + all.byresp$test_most_projects + all.byresp$test_least_percentvotes + all.byresp$test_enrollment_specific + all.byresp$test_percentvotes_specific)


c.df=data.frame(varmean=NA, group=NA, sd=NA, upper=NA, lower=NA)
c.df[1,]$varmean=mean(c.byresp$test_least_classes, na.rm=TRUE)*100
c.df[1,]$sd=sd(c.byresp$test_least_classes, na.rm=TRUE)*100
c.df[1,]$upper=c.df[1,]$varmean + 1.96*c.df[1,]$sd
c.df[1,]$lower=c.df[1,]$varmean - 1.96*c.df[1,]$sd
c.df[1,]$group="Which school has \nthe least classrooms?"
c.df[2,]$varmean=mean(c.byresp$test_most_enrollment, na.rm=TRUE)*100
c.df[2,]$sd=sd(c.byresp$test_most_enrollment, na.rm=TRUE)*100
c.df[2,]$upper=c.df[2,]$varmean + 1.96*c.df[2,]$sd
c.df[2,]$lower=c.df[2,]$varmean - 1.96*c.df[2,]$sd
c.df[2,]$group="Which school has \nthe most students?"
c.df[3,]$varmean=mean(c.byresp$test_enrollment_specific, na.rm=TRUE)*100
c.df[3,]$sd=sd(c.byresp$test_enrollment_specific, na.rm=TRUE)*100
c.df[3,]$upper=c.df[3,]$varmean + 1.96*c.df[3,]$sd
c.df[3,]$lower=c.df[3,]$varmean - 1.96*c.df[3,]$sd
c.df[3,]$group="How many are enrolled in \nthis school?"
c.df[4,]$varmean=mean(c.byresp$test_least_percentvotes, na.rm=TRUE)*100
c.df[4,]$sd=sd(c.byresp$test_least_percentvotes, na.rm=TRUE)*100
c.df[4,]$upper=c.df[3,]$varmean + 1.96*c.df[3,]$sd
c.df[4,]$lower=c.df[3,]$varmean - 1.96*c.df[3,]$sd
c.df[4,]$group="In which school did you \nreceived lowest percent votes?"
c.df[5,]$varmean=mean(c.byresp$test_percentvotes_specific, na.rm=TRUE)*100
c.df[5,]$sd=sd(c.byresp$test_percentvotes_specific, na.rm=TRUE)*100
c.df[5,]$upper=c.df[3,]$varmean + 1.96*c.df[3,]$sd
c.df[5,]$lower=c.df[3,]$varmean - 1.96*c.df[3,]$sd
c.df[5,]$group="What were the \npercent votes in this school?"
c.df[6,]$varmean=mean(c.byresp$test_most_projects, na.rm=TRUE)*100
c.df[6,]$sd=sd(c.byresp$test_most_projects, na.rm=TRUE)*100
c.df[6,]$upper=c.df[3,]$varmean + 1.96*c.df[3,]$sd
c.df[6,]$lower=c.df[3,]$varmean - 1.96*c.df[3,]$sd
c.df[6,]$group="Which school has the most\n donor projects?"
c.df[7,]$varmean=mean(c.byresp$test_donor_specific, na.rm=TRUE)*100
c.df[7,]$sd=sd(c.byresp$test_donor_specific, na.rm=TRUE)*100
c.df[7,]$upper=c.df[3,]$varmean + 1.96*c.df[3,]$sd
c.df[7,]$lower=c.df[3,]$varmean - 1.96*c.df[3,]$sd
c.df[7,]$group="What are the name(s) \nof the donor(s) at this school?"


c.df$group2=factor(c.df$group, 
                 levels=names(sort(table(c.df$group), 
                                   decreasing=FALSE)))



#create dataframe to plot summary data
mp.df=data.frame(varmean=NA, group=NA, sd=NA, upper=NA, lower=NA)
mp.df[1,]$varmean=mean(mp.byresp$test_least_classes, na.rm=TRUE)*100
mp.df[1,]$sd=sd(mp.byresp$test_least_classes, na.rm=TRUE)*100
mp.df[1,]$upper=mp.df[1,]$varmean + 1.96*mp.df[1,]$sd
mp.df[1,]$lower=mp.df[1,]$varmean - 1.96*mp.df[1,]$sd
mp.df[1,]$group="Which school has \nthe least classrooms?"
mp.df[2,]$varmean=mean(mp.byresp$test_most_enrollment, na.rm=TRUE)*100
mp.df[2,]$sd=sd(mp.byresp$test_most_enrollment, na.rm=TRUE)*100
mp.df[2,]$upper=mp.df[2,]$varmean + 1.96*mp.df[2,]$sd
mp.df[2,]$lower=mp.df[2,]$varmean - 1.96*mp.df[2,]$sd
mp.df[2,]$group="Which school has \nthe most students?"
mp.df[3,]$varmean=mean(mp.byresp$test_enrollment_specific, na.rm=TRUE)*100
mp.df[3,]$sd=sd(mp.byresp$test_enrollment_specific, na.rm=TRUE)*100
mp.df[3,]$upper=mp.df[3,]$varmean + 1.96*mp.df[3,]$sd
mp.df[3,]$lower=mp.df[3,]$varmean - 1.96*mp.df[3,]$sd
mp.df[3,]$group="How many are enrolled in \nthis school?"
mp.df[4,]$varmean=mean(mp.byresp$test_least_percentvotes, na.rm=TRUE)*100
mp.df[4,]$sd=sd(mp.byresp$test_least_percentvotes, na.rm=TRUE)*100
mp.df[4,]$upper=mp.df[3,]$varmean + 1.96*mp.df[3,]$sd
mp.df[4,]$lower=mp.df[3,]$varmean - 1.96*mp.df[3,]$sd
mp.df[4,]$group="In which school did you \nreceived lowest percent votes?"
mp.df[5,]$varmean=mean(mp.byresp$test_percentvotes_specific, na.rm=TRUE)*100
mp.df[5,]$sd=sd(mp.byresp$test_percentvotes_specific, na.rm=TRUE)*100
mp.df[5,]$upper=mp.df[3,]$varmean + 1.96*mp.df[3,]$sd
mp.df[5,]$lower=mp.df[3,]$varmean - 1.96*mp.df[3,]$sd
mp.df[5,]$group="What were the \npercent votes in this school?"
mp.df[6,]$varmean=mean(mp.byresp$test_most_projects, na.rm=TRUE)*100
mp.df[6,]$sd=sd(mp.byresp$test_most_projects, na.rm=TRUE)*100
mp.df[6,]$upper=mp.df[3,]$varmean + 1.96*mp.df[3,]$sd
mp.df[6,]$lower=mp.df[3,]$varmean - 1.96*mp.df[3,]$sd
mp.df[6,]$group="Which school has the most\n donor projects?"
mp.df[7,]$varmean=mean(mp.byresp$test_donor_specific, na.rm=TRUE)*100
mp.df[7,]$sd=sd(mp.byresp$test_donor_specific, na.rm=TRUE)*100
mp.df[7,]$upper=mp.df[3,]$varmean + 1.96*mp.df[3,]$sd
mp.df[7,]$lower=mp.df[3,]$varmean - 1.96*mp.df[3,]$sd
mp.df[7,]$group="What are the name(s) \nof the donor(s) at this school?"

mp.df$group2=factor(mp.df$group, 
                   levels=names(sort(table(mp.df$group), 
                                     decreasing=FALSE)))

mp.df$Respondent="MPs"
c.df$Respondent="LCs"
random.df$Respondent="Random Baseline"

all.df=rbind(mp.df, c.df, random.df)




p=ggplot(all.df, aes(y=varmean, x=reorder(group, varmean), fill=Respondent)) + 
  geom_bar(position=position_dodge(), stat="identity", width=0.5) +
  
  
  theme_bw() +
  theme(
    axis.title.x = element_text(family="sans",  size=12),
    axis.title.y = element_text(family="sans",  size=12),
    axis.text.x  = element_text(family="sans",  size=12),
    axis.text.y  = element_text(family="sans",  size=12),
    legend.text = element_text(family="sans",  size=12),
    legend.title = element_blank(),
    text=element_text(family="sans"), 
    legend.position = c(0.40, 0.03),
    legend.justification = c(0, 0), 
    legend.background = element_rect(colour="black", size=0.3)
  )+
  labs(y = "Percent Responding Correctly", x="")+
  ggtitle("")+
  expand_limits(y=c(0,70))+
  scale_fill_manual(values=c(wes_palette(n=2, name="IsleofDogs2"),"black"))+
  coord_flip()

pdf("./Output/all_priorplot.pdf",width=7,height=4)
p
dev.off()
p
```


\subsection{Questions on the Usefulness of Information (Figures S11, S12, S13)}

```{r learning, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

#this is a politician level dataset containing post-treatment questions on the usefulness of information
survey=read.csv("./data/how_useful_survey_questions.csv")

p=ggplot(survey, aes(x=all.aid_61)) + 
  geom_bar(fill=wes_palette(name="IsleofDogs2")[3])+
  ylab("Number of Respondents")+
  xlab(" ")+
    theme_bw() +
  theme(text = element_text(size = 14), plot.title =  element_text(size = 14))+
  ggtitle("Today we have provided you with several pieces of information about \n schools in your community. How useful did you find this information?")

pdf("./Output/howuseful.pdf",width=7, height=5, family="Helvetica")
p
dev.off()
p

#create one variable encompassing the (potentially) two answers to usefulness question
usefulinfo1=survey
usefulinfo2=survey
usefulinfo2$categories=usefulinfo2$categories.1
usefulinfo2=usefulinfo2[nchar(usefulinfo2$categories)>0,]
usefulinfo= rbind(usefulinfo1, usefulinfo2)   
usefulinfo=usefulinfo[!is.na(usefulinfo$categories) & nchar(usefulinfo$categories)>0,]
usefulinfo=usefulinfo[usefulinfo$categories !="Non responsive",]


usefulinfo$categories=str_wrap(usefulinfo$categories, width=30)

this.usefulinfo <- within(usefulinfo, 
                   categories <- factor(categories, 
                                      levels=names(sort(table(categories), 
                                                        decreasing=TRUE))))  

N=nrow(usefulinfo1)
p= ggplot(this.usefulinfo, aes(x=categories)) + 
  geom_bar(fill=wes_palette(name="IsleofDogs2")[3])+
  xlab(" ")+
    ylab("Number of Respondents")+
  ggtitle(paste0("How did this information influence your decision?\n", "(N valid responses=", N, ")"))+
  coord_flip()+
      theme_bw() +
      theme(text = element_text(size = 16), plot.title =  element_text(size = 16))

pdf("./Output/howuseful_detail.pdf",width=8, height=10, family="Helvetica")
p
dev.off()
p

survey$all.aid_63=ifelse(is.na(survey$all.aid_63), "Don't know/Declined", survey$all.aid_63)
survey$all.aid_63=ifelse(grepl( "*know",survey$all.aid_63), "Don't Know/Declined", survey$all.aid_63)

p=ggplot(survey, aes(x=all.aid_63)) + 
  geom_bar(fill=wes_palette(name="IsleofDogs2")[3])+
  xlab(" ")+
    ylab("Number of Respondents")+
    theme_bw() +
    theme(text = element_text(size = 14), plot.title =  element_text(size = 14))+
  ggtitle("Did you learn anything new about schools in your community today?")

pdf("./Output/learning.pdf",width=7, height=5, family="Helvetica")
p
dev.off()
p



```


\section{Attrition, Compliance and Bias}


\subsection{Attrition Statistics (Table S42, S43, S44, S45) }
```{r, message=FALSE, warning=FALSE, results='asis', echo=F}


#Attrition summary statistics
summarytable=data.frame(Variable=NA, NotAttritted=NA, Attritted=NA,  Difference=NA)



for(this.dfname in c("c.survey.all", "mp.survey.all")){
  j=0
  model="1"
  for(i in 1:nrow(labels)){
    if(grepl("*knowledge*", labels[i,]$varname)){next}
    if(grepl("*understand*", labels[i,]$varname)){next}

    this.df=eval(parse(text=this.dfname))
    if(this.dfname=="mp.survey.all"){this.df$id=this.df$constituencyid}
    if(this.dfname=="c.survey.all"){this.df$id=this.df$ps_ward_id}
    
  
    
      
    eval(parse(text=paste("this.df$tempvar=this.df$", labels[i,]$varname, sep="")))

    this.df.unique=aggregate(this.df$attritted, by=list(this.df$id), max)
    this.df.unique$id= this.df.unique$Group.1
    this.df.unique$attritted= this.df.unique$x
    
    N=nrow(this.df.unique)
    N.att0=nrow(this.df.unique[this.df.unique$attritted==0,])
    N.att1=nrow(this.df.unique[this.df.unique$attritted==1,])
    
    m.att0=mean(this.df[!is.na(this.df$tempvar) & this.df$attritted==0,]$tempvar)
    m.att1=mean(this.df[!is.na(this.df$tempvar) & this.df$attritted==1,]$tempvar)
    
    sd.att0=sd(this.df[!is.na(this.df$tempvar) & this.df$attritted==0,]$tempvar)
    sd.att1=sd(this.df[!is.na(this.df$tempvar) & this.df$attritted==1,]$tempvar)
    
    m.diff=m.att1-m.att0
    sd.diff=sqrt((sd.att0^2/N.att0)+(sd.att1^2/N.att1))
    
    if(!is.na(m.att1) & N.att1>0){
      j=j+1
      summarytable[j,]$Variable=labels[i,]$label
      summarytable[j,]$NotAttritted=paste(round(m.att0,3)," (", round(sd.att0,3), ")", sep="")
      summarytable[j,]$Attritted=paste(round(m.att1,3)," (", round(sd.att1,3), ")", sep="")
      summarytable[j,]$Difference=paste(round(m.diff,3)," (", round(sd.diff,3), ")", sep="")
      ag=aggregate(this.df$tempvar, by=list(this.df$id), FUN=mean, na.rm=TRUE)
      assign(paste("m_", labels[i,]$varname, sep=""), ag$x)
      model=paste(model, paste("m_", labels[i,]$varname, sep=""), sep=" + ")
    }
    
  }
  m_attritted=this.df.unique$attritted
  m=lm(as.formula(paste("m_attritted", model, sep="~")))
  summary(m)

  assign(paste("m_", this.dfname, sep=""), m)

print(xtable(summarytable,  label=paste("tab_attrition_", this.dfname, sep=""), caption="Summary Statistics by Survey Attrition Status"), include.rownames=FALSE, file=paste("./output/attrition_summary_", this.dfname, ".tex", sep=""), caption.placement = "top", hline.after=c(-1, 0), tabular.environment = "longtable")

print(xtable(summarytable,  label=paste("tab_attrition_", this.dfname, sep=""), caption="Summary Statistics by Survey Attrition Status"), include.rownames=FALSE, caption.placement = "top", hline.after=c(-1, 0), tabular.environment = "longtable")
}

#note stargazer does not support long tables
stargazer(m_mp.survey.all, m_c.survey.all, type = "latex", 
          out=paste("./output/attrition_regression.tex", sep=""), 
          column.labels = c( "MP Survey", "Councillor Survey"),
          model.names=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "",
          dep.var.caption  = "",
          title="The Effect of Covariates on Survey Attrition",
          covariate.labels=summarytable$Variable, no.space=TRUE,
          label=paste("tab_attrition_regression", sep=""),
          table.placement = "H"
)

```


```{r attrition_contesting_map, message=FALSE, warning=FALSE, results='asis', eval=T, echo=FALSE}

maps=all.surveys.fullsample[!duplicated(all.surveys.fullsample$map_id),]
m.need = felm(as.formula(paste("mapwithwrongschool ~ information_need | 0 |0|resp_id")),  maps)  
m.aid = felm(as.formula(paste("mapwithwrongschool ~ information_aid | 0 |0|resp_id")),  maps)  
m.votes= felm(as.formula(paste("mapwithwrongschool ~ information_votes | 0 |0|resp_id")),  maps)  
m.all = felm(as.formula(paste("mapwithwrongschool ~ information_need + information_votes + information_aid | 0 |0|resp_id")),  maps)  

sg=capture.output(stargazer(m.need, m.aid,m.votes, m.all, type = "latex", 
          out=paste("./Output/tab_compliance_attrition.tex", sep=""),
          model.names=FALSE, header=FALSE, dep.var.labels.include=FALSE,
          notes = "replace me",         
          dep.var.caption  = "",
          title="Effect of treatment on attrition due to politician contesting a school location",
          order=c("^information_need$", "^information_aid$", "^information_votes$"),
          keep=c("^information_need$", "^information_aid$", "^information_votes$"),
          covariate.labels = c(labelme("information_need"), labelme("information_aid"), labelme("information_votes")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_compliance_attrition", sep=""),
          table.placement = "H",
           add.lines=list(c("N Maps", m.need$N, m.aid$N, m.votes$N, m.all$N))
          
))

stargazer_print(sg, "\\multicolumn{5}{p{\\textwidth}}{This table shows the results of a linear regression. The outcome variable is one if a map is attritted due to politicians contesting map boundaries and zero if the map remains in the analysis sample. Estimates are clustered on respondent. }", "tab_compliance_attrition.tex")



```

\subsection{Tests of Desirability Bias (Tables S20, S21, S22)}
```{r bias plot, message=FALSE, warning=FALSE, echo=FALSE, results='asis', eval=T}


m1.1 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.2 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*heardtearfund + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.3 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*workedtearfund + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


m2.1 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
m2.2 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*heardtearfund + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
m2.3 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*workedtearfund + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)


m3.1 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m3.2 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*heardtearfund + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m3.3 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*workedtearfund + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)





sg=capture.output(stargazer(m1.1, m1.2, m1.3, type = "latex", 
          out=paste("./Output/tab_bias_need.tex", sep=""), 
          column.labels = c("All Surveys","All Surveys", "All Surveys"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects Conditional on Donor Interaction and Tearfund Knowledge",
          order=c("^information_need:school_need_index:donor_frequency$", "^information_need:school_need_index:heardtearfund$",
                  "^information_need:school_need_index:workedtearfund$",
                  "^information_need:school_need_index$","^school_need_index:donor_frequency$", "^school_need_index:heardtearfund$","^school_need_index:workedtearfund$","^school_need_index$"),
          keep=c("^information_need:school_need_index:donor_frequency$", "^information_need:school_need_index:heardtearfund$",
                  "^information_need:school_need_index:workedtearfund$",
                  "^information_need:school_need_index$","^school_need_index:donor_frequency$", "^school_need_index:heardtearfund$","^school_need_index:workedtearfund$","^school_need_index$"),
          omit="*",
          covariate.labels = c(
            paste(labelme("information_need"), labelme("school_need_index"), labelme("donor_frequency_imp"), sep="*\n "), 
             paste(labelme("information_need"), labelme("school_need_index"), labelme("heardtearfund"), sep="*\n "), 
            paste(labelme("information_need"), labelme("school_need_index"), labelme("workedtearfund"), sep="*\n "), 
             paste(labelme("information_need"), labelme("school_need_index"), sep="*\n"),
             paste(labelme("school_need_index"), labelme("donor_frequency_imp"), sep="*\n"),
            paste(labelme("school_need_index"), labelme("heardtearfund"), sep="*\n"),
            paste(labelme("school_need_index"), labelme("workedtearfund"), sep="*\n"),
            labelme("school_need_index")),
            
          no.space=TRUE,
          label=paste("tab_bias_need", sep=""),
          table.placement = "H"
          
))
stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_bias_need.tex")



sg=capture.output(stargazer(m2.1, m2.2, m2.3, type = "latex", 
          out=paste("./Output/tab_bias_need_lc.tex", sep=""), 
          column.labels = c("Councillors","Councillors", "Councillors"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects Conditional on Donor Interaction and Tearfund Knowledge",
          order=c("^information_need:school_need_index:donor_frequency$", "^information_need:school_need_index:heardtearfund$",
                  "^information_need:school_need_index:workedtearfund$",
                  "^information_need:school_need_index$","^school_need_index:donor_frequency$", "^school_need_index:heardtearfund$","^school_need_index:workedtearfund$","^school_need_index$"),
          keep=c("^information_need:school_need_index:donor_frequency$", "^information_need:school_need_index:heardtearfund$",
                  "^information_need:school_need_index:workedtearfund$",
                  "^information_need:school_need_index$","^school_need_index:donor_frequency$", "^school_need_index:heardtearfund$","^school_need_index:workedtearfund$","^school_need_index$"),
          omit="*",
          covariate.labels = c(
            paste(labelme("information_need"), labelme("school_need_index"), labelme("donor_frequency_imp"), sep="*\n "), 
             paste(labelme("information_need"), labelme("school_need_index"), labelme("heardtearfund"), sep="*\n "), 
            paste(labelme("information_need"), labelme("school_need_index"), labelme("workedtearfund"), sep="*\n "), 
             paste(labelme("information_need"), labelme("school_need_index"), sep="*\n"),
             paste(labelme("school_need_index"), labelme("donor_frequency_imp"), sep="*\n"),
            paste(labelme("school_need_index"), labelme("heardtearfund"), sep="*\n"),
            paste(labelme("school_need_index"), labelme("workedtearfund"), sep="*\n"),
            labelme("school_need_index")),
            
          no.space=TRUE,
          label=paste("tab_bias_need_lc", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_bias_need_lc.tex")



sg=capture.output(stargazer(m3.1, m3.2, m3.3, type = "latex", 
          out=paste("./Output/tab_bias_need_mp.tex", sep=""), 
          column.labels = c("MPs", "MPs", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects Conditional on Donor Interaction and Tearfund Knowledge",
          order=c("^information_need:school_need_index:donor_frequency$", "^information_need:school_need_index:heardtearfund$",
                  "^information_need:school_need_index:workedtearfund$",
                  "^information_need:school_need_index$","^school_need_index:donor_frequency$", "^school_need_index:heardtearfund$","^school_need_index:workedtearfund$","^school_need_index$"),
          keep=c("^information_need:school_need_index:donor_frequency$", "^information_need:school_need_index:heardtearfund$",
                  "^information_need:school_need_index:workedtearfund$",
                  "^information_need:school_need_index$","^school_need_index:donor_frequency$", "^school_need_index:heardtearfund$","^school_need_index:workedtearfund$","^school_need_index$"),
          omit="*",
          covariate.labels = c(
            paste(labelme("information_need"), labelme("school_need_index"), labelme("donor_frequency_imp"), sep="*\n "), 
             paste(labelme("information_need"), labelme("school_need_index"), labelme("heardtearfund"), sep="*\n "), 
            paste(labelme("information_need"), labelme("school_need_index"), labelme("workedtearfund"), sep="*\n "), 
             paste(labelme("information_need"), labelme("school_need_index"), sep="*\n"),
             paste(labelme("school_need_index"), labelme("donor_frequency_imp"), sep="*\n"),
            paste(labelme("school_need_index"), labelme("heardtearfund"), sep="*\n"),
            paste(labelme("school_need_index"), labelme("workedtearfund"), sep="*\n"),
            labelme("school_need_index")),
            
          no.space=TRUE,
          label=paste("tab_bias_need_mp", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_bias_need_mp.tex")


m1.1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*heardtearfund + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.3 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*workedtearfund + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


m2.1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
m2.2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*heardtearfund + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
m2.3 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*workedtearfund + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)


m3.1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m3.2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*heardtearfund + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m3.3 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*workedtearfund + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)





sg=capture.output(stargazer(m1.1, m1.2, m1.3, type = "latex", 
          out=paste("./Output/tab_bias_aid.tex", sep=""), 
          column.labels = c("All Surveys","All Surveys", "All Surveys"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects Conditional on Donor Interaction and Tearfund Knowledge",
          order=c("^information_aid:z_past_aid_project:donor_frequency$", "^information_aid:z_past_aid_project:heardtearfund$",
                  "^information_aid:z_past_aid_project:workedtearfund$",
                  "^information_aid:z_past_aid_project$","^z_past_aid_project:donor_frequency$", "^z_past_aid_project:heardtearfund$","^z_past_aid_project:workedtearfund$","^z_past_aid_project$"),
          keep=c("^information_aid:z_past_aid_project:donor_frequency$", "^information_aid:z_past_aid_project:heardtearfund$",
                  "^information_aid:z_past_aid_project:workedtearfund$",
                  "^information_aid:z_past_aid_project$","^z_past_aid_project:donor_frequency$", "^z_past_aid_project:heardtearfund$","^z_past_aid_project:workedtearfund$","^z_past_aid_project$"),
          omit="*",
          covariate.labels = c(
            paste(labelme("information_aid"), labelme("past_aid_project"), labelme("donor_frequency_imp"), sep="*\n "), 
             paste(labelme("information_aid"), labelme("past_aid_project"), labelme("heardtearfund"), sep="*\n "), 
            paste(labelme("information_aid"), labelme("past_aid_project"), labelme("workedtearfund"), sep="*\n "), 
             paste(labelme("information_aid"), labelme("past_aid_project"), sep="*\n"),
             paste(labelme("past_aid_project"), labelme("donor_frequency_imp"), sep="*\n"),
            paste(labelme("past_aid_project"), labelme("heardtearfund"), sep="*\n"),
            paste(labelme("past_aid_project"), labelme("workedtearfund"), sep="*\n"),
            labelme("past_aid_project")),
            
          no.space=TRUE,
          label=paste("tab_bias_aid", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_bias_aid.tex")



sg=capture.output(stargazer(m2.1, m2.2, m2.3, type = "latex", 
          out=paste("./Output/tab_bias_aid_lc.tex", sep=""), 
          column.labels = c("Councillors","Councillors", "Councillors"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects Conditional on Donor Interaction and Tearfund Knowledge",
          order=c("^information_aid:z_past_aid_project:donor_frequency$", "^information_aid:z_past_aid_project:heardtearfund$",
                  "^information_aid:z_past_aid_project:workedtearfund$",
                  "^information_aid:z_past_aid_project$","^z_past_aid_project:donor_frequency$", "^z_past_aid_project:heardtearfund$","^z_past_aid_project:workedtearfund$","^z_past_aid_project$"),
          keep=c("^information_aid:z_past_aid_project:donor_frequency$", "^information_aid:z_past_aid_project:heardtearfund$",
                  "^information_aid:z_past_aid_project:workedtearfund$",
                  "^information_aid:z_past_aid_project$","^z_past_aid_project:donor_frequency$", "^z_past_aid_project:heardtearfund$","^z_past_aid_project:workedtearfund$","^z_past_aid_project$"),
          omit="*",
          covariate.labels = c(
            paste(labelme("information_aid"), labelme("past_aid_project"), labelme("donor_frequency_imp"), sep="*\n "), 
             paste(labelme("information_aid"), labelme("past_aid_project"), labelme("heardtearfund"), sep="*\n "), 
            paste(labelme("information_aid"), labelme("past_aid_project"), labelme("workedtearfund"), sep="*\n "), 
             paste(labelme("information_aid"), labelme("past_aid_project"), sep="*\n"),
             paste(labelme("past_aid_project"), labelme("donor_frequency_imp"), sep="*\n"),
            paste(labelme("past_aid_project"), labelme("heardtearfund"), sep="*\n"),
            paste(labelme("past_aid_project"), labelme("workedtearfund"), sep="*\n"),
            labelme("past_aid_project")),
            
          no.space=TRUE,
          label=paste("tab_bias_aid_lc", sep=""),
          table.placement = "H"
          
))
stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_bias_aid_lc.tex")



sg=capture.output(stargazer(m3.1, m3.2, m3.3, type = "latex", 
          out=paste("./Output/tab_bias_aid_mp.tex", sep=""), 
          column.labels = c("MPs", "MPs", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects Conditional on Donor Interaction and Tearfund Knowledge",
          order=c("^information_aid:z_past_aid_project:donor_frequency$", "^information_aid:z_past_aid_project:heardtearfund$",
                  "^information_aid:z_past_aid_project:workedtearfund$",
                  "^information_aid:z_past_aid_project$","^z_past_aid_project:donor_frequency$", "^z_past_aid_project:heardtearfund$","^z_past_aid_project:workedtearfund$","^z_past_aid_project$"),
          keep=c("^information_aid:z_past_aid_project:donor_frequency$", "^information_aid:z_past_aid_project:heardtearfund$",
                  "^information_aid:z_past_aid_project:workedtearfund$",
                  "^information_aid:z_past_aid_project$","^z_past_aid_project:donor_frequency$", "^z_past_aid_project:heardtearfund$","^z_past_aid_project:workedtearfund$","^z_past_aid_project$"),
          omit="*",
          covariate.labels = c(
            paste(labelme("information_aid"), labelme("past_aid_project"), labelme("donor_frequency_imp"), sep="*\n "), 
             paste(labelme("information_aid"), labelme("past_aid_project"), labelme("heardtearfund"), sep="*\n "), 
            paste(labelme("information_aid"), labelme("past_aid_project"), labelme("workedtearfund"), sep="*\n "), 
             paste(labelme("information_aid"), labelme("past_aid_project"), sep="*\n"),
             paste(labelme("past_aid_project"), labelme("donor_frequency_imp"), sep="*\n"),
            paste(labelme("past_aid_project"), labelme("heardtearfund"), sep="*\n"),
            paste(labelme("past_aid_project"), labelme("workedtearfund"), sep="*\n"),
            labelme("past_aid_project")),
            
          no.space=TRUE,
          label=paste("tab_bias_aid_mp", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_bias_aid_mp.tex")



m1.1 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.2 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*heardtearfund + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)
m1.3 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*workedtearfund + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)


m2.1 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
m2.2 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*heardtearfund + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)
m2.3 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*workedtearfund + strata(map_id) + cluster(resp_id)")), method="efron", c.survey)


m3.1 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*donor_frequency + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m3.2 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*heardtearfund + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)
m3.3 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*workedtearfund + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)





sg=capture.output(stargazer(m1.1, m1.2, m1.3, type = "latex", 
          out=paste("./Output/tab_bias_votes.tex", sep=""), 
          column.labels = c("All Surveys","All Surveys", "All Surveys"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects Conditional on Donor Interaction and Tearfund Knowledge",
          order=c("^information_votes:z_winner_percent:donor_frequency$", "^information_votes:z_winner_percent:heardtearfund$",
                  "^information_votes:z_winner_percent:workedtearfund$",
                  "^information_votes:z_winner_percent$","^z_winner_percent:donor_frequency$", "^z_winner_percent:heardtearfund$","^z_winner_percent:workedtearfund$","^z_winner_percent$"),
          keep=c("^information_votes:z_winner_percent:donor_frequency$", "^information_votes:z_winner_percent:heardtearfund$",
                  "^information_votes:z_winner_percent:workedtearfund$",
                  "^information_votes:z_winner_percent$","^z_winner_percent:donor_frequency$", "^z_winner_percent:heardtearfund$","^z_winner_percent:workedtearfund$","^z_winner_percent$"),
          omit="*",
          covariate.labels = c(
            paste(labelme("information_votes"), labelme("winner_percent"), labelme("donor_frequency_imp"), sep="*\n "), 
             paste(labelme("information_votes"), labelme("winner_percent"), labelme("heardtearfund"), sep="*\n "), 
            paste(labelme("information_votes"), labelme("winner_percent"), labelme("workedtearfund"), sep="*\n "), 
             paste(labelme("information_votes"), labelme("winner_percent"), sep="*\n"),
             paste(labelme("winner_percent"), labelme("donor_frequency_imp"), sep="*\n"),
            paste(labelme("winner_percent"), labelme("heardtearfund"), sep="*\n"),
            paste(labelme("winner_percent"), labelme("workedtearfund"), sep="*\n"),
            labelme("winner_percent")),
            
          no.space=TRUE,
          label=paste("tab_bias_votes", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_bias_votes.tex")

sg=capture.output(stargazer(m2.1, m2.2, m2.3, type = "latex", 
          out=paste("./Output/tab_bias_votes_lc.tex", sep=""), 
          column.labels = c("Councillors","Councillors", "Councillors"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects Conditional on Donor Interaction and Tearfund Knowledge",
          order=c("^information_votes:z_winner_percent:donor_frequency$", "^information_votes:z_winner_percent:heardtearfund$",
                  "^information_votes:z_winner_percent:workedtearfund$",
                  "^information_votes:z_winner_percent$","^z_winner_percent:donor_frequency$", "^z_winner_percent:heardtearfund$","^z_winner_percent:workedtearfund$","^z_winner_percent$"),
          keep=c("^information_votes:z_winner_percent:donor_frequency$", "^information_votes:z_winner_percent:heardtearfund$",
                  "^information_votes:z_winner_percent:workedtearfund$",
                  "^information_votes:z_winner_percent$","^z_winner_percent:donor_frequency$", "^z_winner_percent:heardtearfund$","^z_winner_percent:workedtearfund$","^z_winner_percent$"),
          omit="*",
          covariate.labels = c(
            paste(labelme("information_votes"), labelme("winner_percent"), labelme("donor_frequency_imp"), sep="*\n "), 
             paste(labelme("information_votes"), labelme("winner_percent"), labelme("heardtearfund"), sep="*\n "), 
            paste(labelme("information_votes"), labelme("winner_percent"), labelme("workedtearfund"), sep="*\n "), 
             paste(labelme("information_votes"), labelme("winner_percent"), sep="*\n"),
             paste(labelme("winner_percent"), labelme("donor_frequency_imp"), sep="*\n"),
            paste(labelme("winner_percent"), labelme("heardtearfund"), sep="*\n"),
            paste(labelme("winner_percent"), labelme("workedtearfund"), sep="*\n"),
            labelme("winner_percent")),
            
          no.space=TRUE,
          label=paste("tab_bias_votes_lc", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_bias_votes_lc.tex")



sg=capture.output(stargazer(m3.1, m3.2, m3.3, type = "latex", 
          out=paste("./Output/tab_bias_votes_mp.tex", sep=""), 
          column.labels = c("MPs", "MPs", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects Conditional on Donor Interaction and Tearfund Knowledge",
          order=c("^information_votes:z_winner_percent:donor_frequency$", "^information_votes:z_winner_percent:heardtearfund$",
                  "^information_votes:z_winner_percent:workedtearfund$",
                  "^information_votes:z_winner_percent$","^z_winner_percent:donor_frequency$", "^z_winner_percent:heardtearfund$","^z_winner_percent:workedtearfund$","^z_winner_percent$"),
          keep=c("^information_votes:z_winner_percent:donor_frequency$", "^information_votes:z_winner_percent:heardtearfund$",
                  "^information_votes:z_winner_percent:workedtearfund$",
                  "^information_votes:z_winner_percent$","^z_winner_percent:donor_frequency$", "^z_winner_percent:heardtearfund$","^z_winner_percent:workedtearfund$","^z_winner_percent$"),
          omit="*",
          covariate.labels = c(
            paste(labelme("information_votes"), labelme("winner_percent"), labelme("donor_frequency_imp"), sep="*\n "), 
             paste(labelme("information_votes"), labelme("winner_percent"), labelme("heardtearfund"), sep="*\n "), 
            paste(labelme("information_votes"), labelme("winner_percent"), labelme("workedtearfund"), sep="*\n "), 
             paste(labelme("information_votes"), labelme("winner_percent"), sep="*\n"),
             paste(labelme("winner_percent"), labelme("donor_frequency_imp"), sep="*\n"),
            paste(labelme("winner_percent"), labelme("heardtearfund"), sep="*\n"),
            paste(labelme("winner_percent"), labelme("workedtearfund"), sep="*\n"),
            labelme("winner_percent")),
            
          no.space=TRUE,
          label=paste("tab_bias_votes_mp", sep=""),
          table.placement = "H"
          
))
stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_bias_votes_mp.tex")
  
```



\subsection{Treatment Compliance Tests (Figures S23, S24, S25)}

```{r compliance, message=FALSE, warning=FALSE, echo=FALSE, results='asis'}


h.compliance1 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*notunderstandmap",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

h.compliance1b = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*notunderstandmap + information_aid*z_past_aid_project*mp + ",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

h.compliance2 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*otherschool",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

h.compliance4 = clogit(as.formula(paste("incumbentselected ~ information_aid*z_past_aid_project*othermaterials",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

sg=capture.output(stargazer(h.compliance1, h.compliance2, h.compliance4, type = "latex", 
          out=paste("./Output/tab_compliance_aid.tex", sep=""), 
         model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects by Compliance",
          order=c("^information_aid:z_past_aid_project:notunderstandmap$","^information_aid:z_past_aid_project:otherschool$", "^information_aid:z_past_aid_project:othermaterials$", "^information_aid:z_past_aid_project$", "^z_past_aid_project:notunderstandmap$", "^z_past_aid_project:otherschool$", "^z_past_aid_project:othermaterials$", "^z_past_aid_project$"),
          keep=c("^information_aid:z_past_aid_project:notunderstandmap$","^information_aid:z_past_aid_project:otherschool$",  "^information_aid:z_past_aid_project:othermaterials$", "^information_aid:z_past_aid_project$", "^z_past_aid_project:notunderstandmap$", "^z_past_aid_project:otherschool$", "^z_past_aid_project:othermaterials$", "^z_past_aid_project$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_aid",]$label, labels.all[labels.all$varname=="past_aid_project",]$label, "Misunderstood Maps (Q1.22)", sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_aid",]$label, labels.all[labels.all$varname=="past_aid_project",]$label, "Requested Other School (Q1.71)", sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_aid",]$label, labels.all[labels.all$varname=="past_aid_project",]$label , "Requested Other Goods (Q1.73)", sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_aid",]$label, labels.all[labels.all$varname=="past_aid_project",]$label, sep="*\n"), 
                               paste(labels.all[labels.all$varname=="past_aid_project",]$label, "Misunderstood Maps (Q1.22)", sep="*\n"),   
                               paste(labels.all[labels.all$varname=="past_aid_project",]$label, "Requested Other School (Q1.71)", sep="*\n"),   
                               paste(labels.all[labels.all$varname=="past_aid_project",]$label, "Requested Other Goods (Q1.73)", sep="*\n"),   
                               
                               labels.all[labels.all$varname=="past_aid_project",]$label),
          omit="*",
          no.space=TRUE,
          label=paste("tab_compliance_aid", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_compliance_aid.tex")



h.compliance1 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*notunderstandmap",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

h.compliance1b = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*notunderstandmap + information_need*school_need_index*mp + ",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

h.compliance2 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*otherschool",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

h.compliance4 = clogit(as.formula(paste("incumbentselected ~ information_need*school_need_index*othermaterials",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

sg=capture.output(stargazer(h.compliance1, h.compliance2, h.compliance4, type = "latex", 
          out=paste("./Output/tab_compliance_need.tex", sep=""), 
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects by Compliance",
          order=c("^information_need:school_need_index:notunderstandmap$","^information_need:school_need_index:otherschool$", "^information_need:school_need_index:othermaterials$", "^information_need:school_need_index$", "^school_need_index:notunderstandmap$", "^school_need_index:otherschool$", "^school_need_index:othermaterials$", "^school_need_index$"),
          keep=c("^information_need:school_need_index:notunderstandmap$","^information_need:school_need_index:otherschool$", "^information_need:school_need_index:othermaterials$", "^information_need:school_need_index$", "^school_need_index:notunderstandmap$", "^school_need_index:otherschool$", "^school_need_index:othermaterials$", "^school_need_index$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_need",]$label, labels.all[labels.all$varname=="school_need_index",]$label, "Misunderstood Maps (Q1.22)", sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_need",]$label, labels.all[labels.all$varname=="school_need_index",]$label, "Requested Other School (Q1.71)", sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_need",]$label, labels.all[labels.all$varname=="school_need_index",]$label , "Requested Other Goods (Q1.73)", sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_need",]$label, labels.all[labels.all$varname=="school_need_index",]$label, sep="*\n"), 
                               paste(labels.all[labels.all$varname=="school_need_index",]$label, "Misunderstood Maps (Q1.22)", sep="*\n"),   
                               paste(labels.all[labels.all$varname=="school_need_index",]$label, "Requested Other School (Q1.71)", sep="*\n"),  
                               paste(labels.all[labels.all$varname=="school_need_index",]$label, "Requested Other Goods (Q1.73)", sep="*\n"),   
                               
                               labels.all[labels.all$varname=="school_need_index",]$label),
          omit="*",
          no.space=TRUE,
          label=paste("tab_compliance_need", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_compliance_need.tex")


h.compliance1 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*notunderstandmap",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

h.compliance1b = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*notunderstandmap + information_votes*z_winner_percent*mp + ",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

h.compliance2 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*otherschool",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

h.compliance4 = clogit(as.formula(paste("incumbentselected ~ information_votes*z_winner_percent*othermaterials",controls, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)

sg=capture.output(stargazer(h.compliance1, h.compliance2, h.compliance4, type = "latex", 
          out=paste("./Output/tab_compliance_votes.tex", sep=""), 
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Treatment Effects by Compliance",
          order=c("^information_votes:z_winner_percent:notunderstandmap$","^information_votes:z_winner_percent:otherschool$", "^information_votes:z_winner_percent:othermaterials$", "^information_votes:z_winner_percent$", "^z_winner_percent:notunderstandmap$", "^z_winner_percent:otherschool$",  "^z_winner_percent:othermaterials$", "^z_winner_percent$"),
          keep=c("^information_votes:z_winner_percent:notunderstandmap$","^information_votes:z_winner_percent:otherschool$", "^information_votes:z_winner_percent:othermaterials$", "^information_votes:z_winner_percent$", "^z_winner_percent:notunderstandmap$", "^z_winner_percent:otherschool$", "^z_winner_percent:othermaterials$", "^z_winner_percent$"),
          covariate.labels = c(paste(labels.all[labels.all$varname=="information_votes",]$label, labels.all[labels.all$varname=="winner_percent",]$label, "Misunderstood Maps (Q1.22)", sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_votes",]$label, labels.all[labels.all$varname=="winner_percent",]$label, "Requested Other School (Q1.71)", sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_votes",]$label, labels.all[labels.all$varname=="winner_percent",]$label , "Requested Other Goods (Q1.73)", sep="*\n"), 
                               paste(labels.all[labels.all$varname=="information_votes",]$label, labels.all[labels.all$varname=="winner_percent",]$label, sep="*\n"), 
                               paste(labels.all[labels.all$varname=="winner_percent",]$label, "Misunderstood Maps (Q1.22)", sep="*\n"),   
                               paste(labels.all[labels.all$varname=="winner_percent",]$label, "Requested Other School (Q1.71)", sep="*\n"),                                  paste(labels.all[labels.all$varname=="winner_percent",]$label, "Requested Other Goods (Q1.73)", sep="*\n"),   
                               
                               labels.all[labels.all$varname=="winner_percent",]$label),
          omit="*",
          no.space=TRUE,
          label=paste("tab_compliance_votes", sep=""),
          table.placement = "H"
          
))


stargazer_print(sg, "\\multicolumn{4}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}", "tab_compliance_votes.tex")


```




\section{Politician Visits (Figure 2, Table S1)}

```{r distanceandvisits, message=FALSE, warning=FALSE, echo=FALSE, results='asis', eval=T}


q=quantile(schools.lc$school_home_distance, na.rm=T, probs=seq(0, 1, 0.25))


est=data.frame(i=NA, coef=NA, upper=NA, lower=NA, val=NA)

for(i in c(1:4)){
  tmp=citizen_survey[citizen_survey$school_home_distance>q[i] & citizen_survey$school_home_distance<q[i+1], ]
  m=lm(councillor_visited1~1, data=tmp)
 ci=coefci(m, cluster = ~schoolid)
 fm=felm(councillor_visited1~1 |0|0|schoolid, data=tmp)
 assign(paste0("m", i), fm)
  coef=m$coefficients[1]
  upper=ci[2]
  lower=ci[1]
  est=rbind(est,data.frame(i=i, coef, upper, lower, val=names(q[i+1])))
}

est=est[-1,]


m_linear= felm(councillor_visited1~log(school_home_distance+1) |0|0|schoolid, data=citizen_survey)

stargazer(m_linear, m1, m2,m3,m4, type = "latex", 
          out=paste("./Output/tab_citizen_visits.tex", sep=""), 
 column.labels = c("Linear Effect", "0-25 perc.", "25-50 perc.","50-75 perc.","75-100 perc."),
 model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "",
          dep.var.caption  = "",
          covariate.labels=c(labelme("school_home_distance"),"Intercept"),
          title="Estimates from Main Text Figure 2",
          no.space=TRUE,
          label=paste("tab_citizen_visits.tex", sep=""),
          table.placement = "H"
          
)

                      
pd <- position_dodge(0.01) # move them .05 to the left and right

p=ggplot(est, aes(x=i, y=coef)) + 
    geom_errorbar(aes(ymin=lower, ymax=upper), colour="black", width=.1, position=pd) +
     geom_line() +
    geom_point(position=pd, size=3, shape=21) + # 21 is filled circle
     xlab("Distance from incumbent's hometown \n(percentile)") +
    ylab("Share of citizens visited by the incumbent") +
    expand_limits(y=c(0, 0.5)) +
    scale_y_continuous(breaks=seq(0,1, by=0.1)) +         # Set tick every 4
    theme_bw() +
    theme(legend.justification=c(1,0),
          legend.position=c(1,0))     +
  scale_x_continuous(breaks=c(1:4), labels=c("0-25%", "25-50%","50-75%","75-100%"))


pdf("./Output/visits_plot.pdf",width=3.5, height=3.5, family="Helvetica")
p
dev.off()
p


```

\section{Politician Learning (Figure 1)}

```{r learning_constituents, message=FALSE, warning=FALSE, echo=FALSE, results='asis', eval=T}
followupsurvey.ag=aggregate(followupsurvey, FUN=count, by=list(followupsurvey$ID))


vars=names(followupsurvey)[grep("Info_",names(followupsurvey))]

followupsurvey.small=followupsurvey[,c(vars)]
followupsurvey.small[is.na(followupsurvey.small)]=0

plotme=data.frame(varname=NA, varmean=NA)
plotme[1,]$varname="Area and Village \nDevelopment Committees"
plotme[1,]$varmean=mean(followupsurvey.small$Info_ADC_VDC)*100

plotme[2,]$varname="Direct Communication \nfrom Citizens"
plotme[2,]$varmean=mean(followupsurvey.small$Info_citizens_teachers)*100

plotme[3,]$varname="District Assemblies"
plotme[3,]$varmean=mean(followupsurvey.small$Info_Assembly)*100

plotme[4,]$varname="District Bureaucrats"
plotme[4,]$varmean=mean(followupsurvey.small$Info_district_bureaucrats)*100

plotme[5,]$varname="Visits to Local Areas"
plotme[5,]$varmean=mean(followupsurvey.small$Info_visits)*100

plotme[6,]$varname="Chiefs"
plotme[6,]$varmean=mean(followupsurvey.small$Info_chief)*100

plotme$varname=fct_inorder(plotme$varname)

p=ggplot(plotme, aes(y=varmean, x=varname)) + 
  geom_bar(position=position_dodge(), stat="identity", fill=wes_palette(n=2, name="Darjeeling1")[2], width=0.5) +
  theme_bw() +
  theme(
    axis.title.x = element_text( size=12),
    axis.title.y = element_text( size=12),
    axis.text.x  = element_text( size=12),
    axis.text.y  = element_text( size=12),
    title  = element_text( size=12))+
  labs(y = "% Respondents", x="")+

  expand_limits(y=c(0,85))+
  coord_flip()+
ggtitle("When making decisions about development, in what\n ways do you learn about things your constituents need?")+ theme(plot.title = element_text(hjust = 1.1))


pdf("./Output/learning_constituents.pdf",width=6, height=4.5, family="Helvetica")
p
dev.off()
p


```

\section{Head Teacher Prioritization of School Needs (Figure S19)}

```{r priorities_schoolneeds, message=FALSE, warning=FALSE, echo=FALSE, results='asis', eval=T}
pdf("./Output/priorities.pdf",width=6, height=4.5, family="Helvetica")
par(mfrow = c(2, 1))
priority1 <- ggplot(headteacher_survey, aes(x=reorder(Priority1, Priority1, function(x)-length(x)))) + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) + geom_bar(fill='gray') + labs(x="", y="N Respondents") + labs(main="Priority One")
priority2 <- ggplot(headteacher_survey, aes(x=reorder(Priority2, Priority2, function(x)-length(x)))) + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) + geom_bar(fill='gray') + labs(x="", y="N Respondents") + labs(main="Priority Two")
priorities <- priority1 + priority2 + plot_annotation(title = "'In your view, what are the top three priorities for school needs at this school?' N=315") & theme(plot.title = element_text(hjust = 0.5, size=10))
priorities
dev.off()
priorities


```

\section{Power Analysis (Figures S1 and S2)}

```{r power, message=FALSE, warning=FALSE, results='asis', echo=FALSE}
#note this chunk relies on pre-processed simulation data. The code to create the simulation data for the power analysis is excluded here due to extent of processing time and reliance on additional pre-experimental data on school characteristics which is not needed for the main analysis.
#Please contact the authors if you would like a copy of this code. 

#for main treatment effects
sims=300
n.politicians=460

this.results.df=read.csv(".\\data\\power_sim.csv")


calc_power05=function(df){
  return(mean(df$this.pval<=0.05))
}
calc_power10=function(df){
  return(mean(df$this.pval<=0.10))
}

this.results.df$this.pval=this.results.df$zt.pval.clogit
this.results.df$this.coef=this.results.df$t.effect




power10=this.results.df %>% 
  group_by(this.coef) %>%
  do(data.frame(power=calc_power10(.)))


power05=this.results.df %>% 
  group_by(this.coef) %>%
  do(data.frame(power=calc_power05(.)))


power05$level="p<0.05"
power10$level="p<0.10"
power.df=rbind(power05,power10)


ggplot(power.df, aes(x=this.coef, y=power, group=level)) +
  geom_line(aes(color=level))+
  geom_point()+
  xlab("b2")+
  ggtitle(paste0("Power for main treatment effect (H1)"))+
  labs(caption=paste0("Number of politicians=", n.politicians, ";\n Number of maps=", n.politicians*3, ";\n Number of simulations=", sims))+
  scale_x_continuous("b2", labels = seq(0.02,0.15, 0.02), breaks = seq(0.02,0.15, 0.02))+
    theme(text = element_text(size = 16)) 

ggsave(".\\output\\power_main.pdf")

#for interaction treatment effects

sims=100
t.effect=0.09 #assumed baseline effect for t

this.results.df=read.csv(".\\data\\power_sim_interaction.csv")


calc_power05=function(df){
  return(mean(df$this.pval<=0.05))
}
calc_power10=function(df){
  return(mean(df$this.pval<=0.10))
}

this.results.df$this.pval=this.results.df$ztw.pval.clogit.interaction
this.results.df$this.coef=this.results.df$w.effect_zt


power10=this.results.df %>% 
  group_by(this.coef) %>%
  do(data.frame(power=calc_power10(.)))


power05=this.results.df %>% 
  group_by(this.coef) %>%
  do(data.frame(power=calc_power05(.)))


power05$level="p<0.05"
power10$level="p<0.10"
power.df=rbind(power05,power10)


ggplot(power.df, aes(x=this.coef, y=power, group=level)) +
  geom_line(aes(color=level))+
  geom_point()+
  xlab("b6")+
  ggtitle(paste0("Power for transparency effect (H5)"))+
  labs(caption=paste0("Number of politicians=", n.politicians, ";\n Number of maps=", n.politicians*3, ";\n Number of simulations=", sims, ";\n assumed b3=", t.effect))+
scale_x_continuous("b6", labels = as.character(seq(0.1,0.3, 0.04)), breaks = seq(0.1,0.3, 0.04))+
  theme(text = element_text(size = 16)) 

ggsave(".\\output\\power_interaction.pdf")
```




\section{Summary Statistics}

\subsection{Number of Maps Receiving Different Combinations of Transparency and Information Treatments (Table S47)}
```{r, message=FALSE, warning=FALSE, results='asis', echo=F}

all.surveys <- all.surveys %>%
  mutate(transparency_condition2 = case_when(Transparency_Condition == 'control' ~ 'Control',
                                             Transparency_Condition == 'donor_audit' ~ 'Donor Audit',
                                             Transparency_Condition == 'donor_audit + radio' ~ 'Radio + Donor Audit',
                                             Transparency_Condition == 'radio + donor_audit' ~ 'Radio + Donor Audit',
                                             Transparency_Condition == 'both' ~ 'Radio + Donor Audit',
                                             Transparency_Condition == 'placebo' ~ 'Control',
                                             Transparency_Condition == 'radio' ~ 'Radio'))

all.surveys <- all.surveys %>% mutate(information_condition2 = case_when(information_aid==0 & information_need==0 & information_votes==0 ~ 'Control',
                                                                                                information_aid==0 & information_need==0 & information_votes==1 ~ 'Political Support (PS)',
                                                                                                information_aid==0 & information_need==1 & information_votes==0 ~ 'School Need (SN)',
                                                                                                information_aid==1 & information_need==0 & information_votes==0 ~ 'Aid',
                                                                                                information_aid==0 & information_need==1 & information_votes==1 ~ 'PS + SN',
                                                                                                information_aid==1 & information_need==0 & information_votes==1 ~ 'PS + Aid',
                                                                                                information_aid==1 & information_need==1 & information_votes==0 ~ 'SN + Aid',
                                                                                                information_aid==1 & information_need==1 & information_votes==1 ~ 'PS + SN + Aid'))

all.surveys = apply_labels(all.surveys,transparency_condition2="Transparency Treatments",information_condition2="Information Treatments")
all.surveys <- all.surveys[order(all.surveys$map_id),]
all.surveys.unique.mapid <- all.surveys[!duplicated(all.surveys$map_id),]

crosstable <- table(all.surveys.unique.mapid$information_condition2, all.surveys.unique.mapid$transparency_condition2)
crosstable_sum <- addmargins(crosstable)
print(xtable(crosstable_sum, align=c("|l", "|l", "|l", "|l", "|l", "|l|"), type = "latex", digits=0), file="./Output/crosstable.tex", caption.placement = "top", hline.after=c(-1,0,8,9))
print(xtable(crosstable_sum, align=c("|l", "|l", "|l", "|l", "|l", "|l|"), type = "latex", digits=0), caption.placement = "top", hline.after=c(-1,0,8,9))

```

\subsection{Local Councillor Sample Statistics (Table S38)}
```{r, message=FALSE, warning=FALSE, results='asis', echo=F}

#for summary stats we have to reload the labels so we're not just working with alternative specific variables
labels=read.csv("./data/labels.csv",stringsAsFactors=FALSE)
labels=labels[labels$include==1,]
labels=subset(labels, !is.na(varname))
labels = labels[order(labels$label),]


summarytable=data.frame(Variable=NA, In_Sample=NA,  Out_of_Sample=NA, Difference=NA)
schools.lc$constituencyid=as.integer(factor(schools.lc$constituencyid))
schools.lc$ps_ward_id=as.integer(factor(schools.lc$ps_ward_id))
schools.mp$constituencyid=as.integer(factor(schools.mp$constituencyid))
schools.mp$ps_ward_id=as.integer(factor(schools.mp$ps_ward_id))

schools.lc=select_if(schools.lc, is.numeric)

schools.mp=select_if(schools.mp, is.numeric)



schools.lc.mean=aggregate(schools.lc, list(c(schools.lc$ps_ward_id)), mean)
schools.lc.sum=aggregate(schools.lc, list(c(schools.lc$ps_ward_id)), sum)

schools.lc.sum$insample=ifelse(schools.lc.sum$insample>0,1,schools.lc.sum$insample)

schools.mp.mean=aggregate(schools.mp, list(c(schools.mp$constituencyid)), mean)
schools.mp.sum=aggregate(schools.mp, list(c(schools.mp$constituencyid)), sum)
schools.mp.sum$insample=ifelse(schools.mp.sum$insample>0,1,schools.mp.sum$insample)


#LC Sample
varlist=data.frame(
  var_name=c("school_enrollment_total", "school_num_teachers", "student_to_teacher_ratio", "past_aid_project", "num_schools_in_ward_tot", "total_turnout", "total_vm", "total_regvoters", "total_percent", "DPP", "UDF", "MCP", "PP", "Independent", "pop_per_hectacre"), 
  label=c("Mean School Enrollment", "Mean Number of Teachers", "Mean Student to Teacher Ratio", "Number of Aid Projects", "Number of Schools", "Turnout", "Incumbent Victory Margin", "Registered Voters", "Incumbent Percent", "DPP Incumbent", "UDF Incumbent", "MCP Incumbent", "PP Incumbent", "Independent Incumbent", "Average School Population Density"), 
  df=c("schools.lc.mean", "schools.lc.mean", "schools.lc.mean", "schools.lc.sum", "schools.lc.mean", "schools.lc.mean", "schools.lc.mean", "schools.lc.mean", "schools.lc.mean","schools.lc.mean","schools.lc.mean","schools.lc.mean","schools.lc.mean","schools.lc.mean", "schools.lc.mean"),
  stringsAsFactors = FALSE)

j=0

for(var in varlist$var_name){
  j=j+1
  eval(parse(text=paste("this.df=",varlist[j,]$df, sep="")))

  eval(parse(text=paste("this.df$this.var=", varlist[j,]$df,"$", var, sep="")))
  
  N=nrow(this.df)
  N.insample=nrow(this.df[this.df$insample==1,])
  N.outsample=nrow(this.df[this.df$insample==0,])
  m.insample = mean(this.df[!is.na(this.df$this.var) & this.df$insample==1,]$this.var)
  m.outsample = mean(this.df[!is.na(this.df$this.var) & this.df$insample==0,]$this.var)
  s.insample = sd(this.df[!is.na(this.df$this.var) & this.df$insample==1,]$this.var)
  s.outsample = sd(this.df[!is.na(this.df$this.var) & this.df$insample==0,]$this.var)
  m.diff=m.insample-m.outsample
  s.diff=sqrt((s.outsample^2/N.outsample)+(s.insample^2/N.outsample))   
  
  summarytable[j,]$Variable=varlist[j,]$label
  summarytable[j,]$In_Sample=paste(round(m.insample,3)," (", round(s.insample,3), ")", sep="")
  summarytable[j,]$Out_of_Sample=paste(round(m.outsample,3)," (", round(s.outsample,3), ")", sep="")
  summarytable[j,]$Difference=paste(round(m.diff,3)," (", round(s.diff,3), ")", sep="")

}
print(xtable(summarytable,  label="tab_sample_lc", caption="Local Councillor Sample Statistics"), include.rownames=FALSE,  caption.placement = "top", file=paste("./output/tab_sample_lc.tex", sep=""), hline.after=c(-1, 0), tabular.environment = "longtable")
print(xtable(summarytable,  label="tab_sample_lc", caption="Local Councillor Sample Statistics"), include.rownames=FALSE,  caption.placement = "top", hline.after=c(-1, 0), tabular.environment = "longtable")
   
```

\subsection{MP Sample Statistics (Table S39)}
```{r, message=FALSE, warning=FALSE, results='asis', echo=F}


#MP Sample
varlist=data.frame(
  var_name=c("school_enrollment_total", "school_num_teachers", "student_to_teacher_ratio", "past_aid_project", "num_schools_in_constituency_tot", "total_turnout", "total_vm", "total_regvoters", "total_percent", "DPP", "UDF", "MCP", "PP", "Independent", "pop_per_hectacre"), 
  label=c("Mean School Enrollment", "Mean Number of Teachers", "Mean Student to Teacher Ratio", "Number of Aid Projects", "Number of Schools", "Turnout", "Incumbent Victory Margin", "Registered Voters", "Incumbent Percent", "DPP Incumbent", "UDF Incumbent", "MCP Incumbent", "PP Incumbent", "Independent Incumbent", "Average School Population Density"), 
  df=c("schools.mp.mean", "schools.mp.mean", "schools.mp.mean", "schools.mp.sum", "schools.mp.mean", "schools.mp.mean", "schools.mp.mean", "schools.mp.mean", "schools.mp.mean","schools.mp.mean","schools.mp.mean","schools.mp.mean","schools.mp.mean","schools.mp.mean", "schools.mp.mean"),
  stringsAsFactors = FALSE)


j=0
for(var in varlist$var_name){
  j=j+1
  eval(parse(text=paste("this.df=",varlist[j,]$df, sep="")))

  eval(parse(text=paste("this.df$this.var=", varlist[j,]$df,"$", var, sep="")))
  

  N=nrow(this.df)
  N.insample=nrow(this.df[this.df$insample==1,])
  N.outsample=nrow(this.df[this.df$insample==0,])
  m.insample = mean(this.df[!is.na(this.df$this.var) & this.df$insample==1,]$this.var)
  m.outsample = mean(this.df[!is.na(this.df$this.var) & this.df$insample==0,]$this.var)
  s.insample = sd(this.df[!is.na(this.df$this.var) & this.df$insample==1,]$this.var)
  s.outsample = sd(this.df[!is.na(this.df$this.var) & this.df$insample==0,]$this.var)
  m.diff=m.insample-m.outsample
  s.diff=sqrt((s.outsample^2/N.outsample)+(s.insample^2/N.outsample))   
  
  summarytable[j,]$Variable=varlist[j,]$label
  summarytable[j,]$'In Sample'=paste(round(m.insample,3)," (", round(s.insample,3), ")", sep="")
  summarytable[j,]$'Out of Sample'=paste(round(m.outsample,3)," (", round(s.outsample,3), ")", sep="")
  summarytable[j,]$Difference=paste(round(m.diff,3)," (", round(s.diff,3), ")", sep="")

}
print(xtable(summarytable,  label="tab_sample_mp", caption="MP Sample Statistics"), include.rownames=FALSE,  caption.placement = "top", file=paste("./output/tab_sample_mp.tex", sep=""), hline.after=c(-1, 0), tabular.environment = "longtable")
print(xtable(summarytable,  label="tab_sample_mp", caption="MP Sample Statistics"), include.rownames=FALSE,  caption.placement = "top", hline.after=c(-1, 0), tabular.environment = "longtable")

```


\subsection{Variable Summary Statistics (Figures S40-S41)}
```{r, message=FALSE, warning=FALSE, results='asis', echo=F}

#Summary Statistics
summarytable=data.frame(Variable=NA, Mean=NA, SD=NA,  Details=NA)
for(this.dfname in c("mp.survey", "c.survey")){
  j=0
  model="1"
  for(i in 1:nrow(labels.all)){
    this.df=eval(parse(text=this.dfname))
    if(is.null(eval(parse(text=paste("this.df$", labels.all[i,]$varname, sep=""))))){next}
    if(grepl("z_", labels.all[i,]$varname)){ next}
  
    eval(parse(text=paste("this.df$tempvar=this.df$", labels.all[i,]$varname, sep="")))

   m=mean(this.df[!is.na(this.df$tempvar),]$tempvar)
   sd=sd(this.df[!is.na(this.df$tempvar) ,]$tempvar)

    
    if(!is.na(m)){
      j=j+1
      summarytable[j,]$Variable=labels.all[i,]$label
      summarytable[j,]$Mean=paste(round(m,3))
      summarytable[j,]$SD=paste(round(sd,3))
      summarytable[j,]$Details=labels.all[i,]$label_description
    }
    
  }

if(this.dfname=="c.survey"){cap="Summary Statistics, LCs"}
if(this.dfname=="mp.survey"){cap="Summary Statistics, MPs"}
   
 xt= capture.output(print(xtable(summarytable,  label=paste("tab_summary_", this.dfname, sep=""), caption="Summary Statistics, MPs"), include.rownames=FALSE,  caption.placement = "top", hline.after=c(-1, 0), tabular.environment = "longtable"))
  
txt= str_replace(xt, "llll","p{4.0cm}p{1.5cm}p{1.5cm}p{6.5cm}")
fileConn<-file(paste0("./Output/summary_", this.dfname, ".tex"))
writeLines(txt, fileConn)
close(fileConn) 
cat (txt, sep = "\n")
  

}



```

\subsection{Correlation Matrix (Figure S18)}
```{r tab_correlation_matrix, echo=FALSE, message=FALSE, warning=FALSE, results='asis'}

varlist=c("school_need_index", "past_aid_project", "winner_percent_imp", "family_children_attend_school", "number_aid_categories", "pop_density", "temporary_to_permanent_ratio", "student_to_classroom_ratio", "student_to_teacher_ratio", "log_number_of_students")

labellist=unlist(lapply(varlist, function(x) labelme(x)))
                
this.df=subset(all.surveys, select=c(varlist))

var.cor=cor(this.df, use="complete.obs")

row.names(var.cor)=labellist
colnames(var.cor)=labellist


##  different color series
col4 <- colorRampPalette(c("#7F0000", "red", "#FF7F00", "yellow", "#7FFF7F",
                           "cyan", "#007FFF", "blue", "#00007F"))
pdf("./Output/correlationplot.pdf",width=7,height=6, family="Times")
corrplot(var.cor, type = "upper", order = "hclust", method="circle",
         tl.col = "black", tl.srt = 45, tl.cex=0.7, cl.lim=c(-1,1), col=col4(50))
dev.off()

corrplot(var.cor, type = "upper", order = "hclust", method="circle",
         tl.col = "black", tl.srt = 45, tl.cex=0.7, cl.lim=c(-1,1), col=col4(50))


```

\subsection{Statistics for CONSORT Diagram (Figure 6)}
```{r}

all.surveys.byresp=all.surveys.fullsample[!duplicated(all.surveys.fullsample$resp_id),]
all.surveys.bymap=all.surveys.fullsample[!duplicated(all.surveys.fullsample$map_id),]

#number of politicians
nrow(all.surveys.byresp)

#transparency treatments
xtabs(~all.surveys.byresp$transparency_radio+all.surveys.byresp$transparency_donor)

#number of maps
nrow(all.surveys.bymap)

#number of maps excluded
xtabs(~all.surveys.bymap$mapwithwrongschool)

#information treatments
xtabs(~all.surveys.bymap$information_aid + all.surveys.bymap$information_votes + all.surveys.bymap$information_need  )

```


\subsection{Association between School Characteristics and School Selection (Figure 7, Tables S2, S3, S4, S5, S6, and S7)}
```{r unconditional plot, message=FALSE, warning=FALSE, results='asis', echo=FALSE, eval=T}


ha.results=data.frame(term=NA, estimate=NA, std.error=NA, robust.se=NA, statistic=NA, p.value=NA, model=NA)

ha1.c = clogit(as.formula(paste("incumbentselected ~ z_school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_need==0,])  
this.results=tidy(ha1.c)[1,]
this.results$model="LCs"
this.results$term="School Need Index"
ha.results=rbind.fill(ha.results,this.results)

ha1.mp = clogit(as.formula(paste("incumbentselected ~ z_school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey[mp.survey$information_need==0,])  
this.results=tidy(ha1.mp)[1,]
this.results$model="MPs"
this.results$term="School Need Index"
ha.results=rbind.fill(ha.results,this.results)

ha1.all = clogit(as.formula(paste("incumbentselected ~ z_school_need_index + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_need==0,])  
this.results=tidy(ha1.all)[1,]
this.results$model="All"
this.results$term="School Need Index"
ha.results=rbind.fill(ha.results,this.results)

controls.t=gsub("\\+ school_need_index", "", controls)

ha1.c.controls = clogit(as.formula(paste("incumbentselected ~ z_school_need_index", controls.t, "+ strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_need==0,])  
this.results=tidy(ha1.c.controls)[1,]
this.results$model="LCs with controls"
this.results$term="School Need Index"
ha.results=rbind.fill(ha.results,this.results)

ha1.mp.controls = clogit(as.formula(paste("incumbentselected ~ z_school_need_index", controls.t, "+ strata(map_id) + cluster(resp_id)")), method="efron", mp.survey[mp.survey$information_need==0,])  
this.results=tidy(ha1.mp.controls)[1,]
this.results$model="MPs with controls"
this.results$term="School Need Index"
ha.results=rbind.fill(ha.results,this.results)

ha1.all.controls = clogit(as.formula(paste("incumbentselected ~ z_school_need_index", controls.t, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_need==0,])  
this.results=tidy(ha1.all.controls)[1,]
this.results$model="All with controls"
this.results$term="School Need Index"
ha.results=rbind.fill(ha.results,this.results)


sg=capture.output(stargazer(ha1.all, ha1.all.controls, ha1.c, ha1.mp, type = "latex", 
          out=paste("./Output/tab_baseline1.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (School Need Index)",
          order=c("^z_school_need_index$"),
          keep=c("^z_school_need_index$"),
          covariate.labels = c(labelme("school_need_index")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_baseline1", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_baseline1_full}).}"), "tab_baseline1.tex", supress_output=F)



sg=capture.output(stargazer(ha1.all, ha1.all.controls, ha1.c, ha1.mp, type = "latex", 
          out=paste("./Output/tab_baseline1_full.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (School Need Index) with controls",
          order=c("^z_school_need_index$"),
          #keep=c("^z_school_need_index$"),
          keep="*",
          covariate.labels = c(labelme("school_need_index")),
         # omit="*",
          no.space=TRUE,
          label=paste("tab_baseline1_full", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}"), "tab_baseline1_full.tex", supress_output=F)




ha1b.mp = clogit(as.formula(paste("incumbentselected ~ z_school_need_index*z_school_home_distance + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey[mp.survey$information_need==0,])  
m=ha1b.mp
 this.var="z_school_need_index"
  this.treat="z_school_home_distance"
  t=1
  this.results$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.var, ":", this.treat)]*t
  this.results$exp_estimate=exp(this.results$estimate)
  this.results$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.var, ":", this.treat), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.var, ":", this.treat)])
  this.results$p.value=coef(summary(m))[paste0(this.var, ":", this.treat), "Pr(>|z|)"]
  this.results$model="MPs"
  this.results$term="School Need Index \n Far from Hometown"
  ha.results=rbind.fill(ha.results,this.results)

ha1b.all = clogit(as.formula(paste("incumbentselected ~ z_school_need_index*z_school_home_distance + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_need==0,])  
m=ha1b.all
 this.var="z_school_need_index"
  this.treat="z_school_home_distance"
  t=1
  this.results$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.var, ":", this.treat)]*t
  this.results$exp_estimate=exp(this.results$estimate)
  this.results$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.var, ":", this.treat), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.var, ":", this.treat)])
  this.results$p.value=coef(summary(m))[paste0(this.var, ":", this.treat), "Pr(>|z|)"]
this.results$model="All"
this.results$term="School Need Index \n Far from Hometown"
ha.results=rbind.fill(ha.results,this.results)



ha1b.c = clogit(as.formula(paste("incumbentselected ~ z_school_need_index*z_school_home_distance",  "+ strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_need==0,])  
m=ha1b.c
 this.var="z_school_need_index"
  this.treat="z_school_home_distance"
  t=1
  this.results$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.var, ":", this.treat)]*t
  this.results$exp_estimate=exp(this.results$estimate)
  this.results$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.var, ":", this.treat), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.var, ":", this.treat)])
  this.results$p.value=coef(summary(m))[paste0(this.var, ":", this.treat), "Pr(>|z|)"]
this.results$model="LCs"
this.results$term="School Need Index \n Far from Hometown"
ha.results=rbind.fill(ha.results,this.results)




ha1b.c.controls = clogit(as.formula(paste("incumbentselected ~ z_school_need_index*z_school_home_distance", controls.t, "+ strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_need==0,])  
m=ha1b.c.controls
 this.var="z_school_need_index"
  this.treat="z_school_home_distance"
  t=1
  this.results$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.var, ":", this.treat)]*t
  this.results$exp_estimate=exp(this.results$estimate)
  this.results$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.var, ":", this.treat), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.var, ":", this.treat)])
  this.results$p.value=coef(summary(m))[paste0(this.var, ":", this.treat), "Pr(>|z|)"]
this.results$model="LCs with controls"
this.results$term="School Need Index \n Far from Hometown"
ha.results=rbind.fill(ha.results,this.results)

ha1b.mp.controls = clogit(as.formula(paste("incumbentselected ~ z_school_need_index*z_school_home_distance", controls.t, "+ strata(map_id) + cluster(resp_id)")), method="efron", mp.survey[mp.survey$information_need==0,])  
m=ha1b.mp.controls
 this.var="z_school_need_index"
  this.treat="z_school_home_distance"
  t=1
  this.results$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.var, ":", this.treat)]*t
  this.results$exp_estimate=exp(this.results$estimate)
  this.results$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.var, ":", this.treat), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.var, ":", this.treat)])
  this.results$p.value=coef(summary(m))[paste0(this.var, ":", this.treat), "Pr(>|z|)"]
this.results$model="MPs with controls"
this.results$term="School Need Index \n Far from Hometown"
ha.results=rbind.fill(ha.results,this.results)

ha1b.all.controls = clogit(as.formula(paste("incumbentselected ~ z_school_need_index*z_school_home_distance", controls.t, "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_need==0,])  
m=ha1b.all.controls
 this.var="z_school_need_index"
  this.treat="z_school_home_distance"
  t=1
  this.results$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.var, ":", this.treat)]*t
  this.results$exp_estimate=exp(this.results$estimate)
  this.results$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.var, ":", this.treat), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.var, ":", this.treat)])
  this.results$p.value=coef(summary(m))[paste0(this.var, ":", this.treat), "Pr(>|z|)"]
this.results$model="All with controls"
this.results$term="School Need Index \n Far from Hometown"
ha.results=rbind.fill(ha.results,this.results)


ha1b.c.controls = clogit(as.formula(paste("incumbentselected ~ z_school_need_index*z_school_home_distance", "+ strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_need==0,])  
m=ha1b.c.controls
 this.var="z_school_need_index"
  this.treat="z_school_home_distance"
  t=-1
  this.results$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.var, ":", this.treat)]*t
  this.results$exp_estimate=exp(this.results$estimate)
  this.results$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.var, ":", this.treat), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.var, ":", this.treat)])
  this.results$p.value=coef(summary(m))[paste0(this.var, ":", this.treat), "Pr(>|z|)"]
this.results$model="LCs"
this.results$term="School Need Index \n Near to Hometown"
ha.results=rbind.fill(ha.results,this.results)

ha1b.mp.controls = clogit(as.formula(paste("incumbentselected ~ z_school_need_index*z_school_home_distance", "+ strata(map_id) + cluster(resp_id)")), method="efron", mp.survey[mp.survey$information_need==0,])  
m=ha1b.mp.controls
 this.var="z_school_need_index"
  this.treat="z_school_home_distance"
  t=-1
  this.results$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.var, ":", this.treat)]*t
  this.results$exp_estimate=exp(this.results$estimate)
  this.results$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.var, ":", this.treat), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.var, ":", this.treat)])
  this.results$p.value=coef(summary(m))[paste0(this.var, ":", this.treat), "Pr(>|z|)"]
this.results$model="MPs"
this.results$term="School Need Index \n Near to Hometown"
ha.results=rbind.fill(ha.results,this.results)

ha1b.all.controls = clogit(as.formula(paste("incumbentselected ~ z_school_need_index*z_school_home_distance", "+ strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_need==0,])  
m=ha1b.all.controls
 this.var="z_school_need_index"
  this.treat="z_school_home_distance"
  t=-1
  this.results$estimate = m$coefficients[this.var] + m$coefficients[paste0(this.var, ":", this.treat)]*t
  this.results$exp_estimate=exp(this.results$estimate)
  this.results$robust.se = sqrt(coef(summary(m))[this.var, "robust se"]^2 + t^2*coef(summary(m))[paste0(this.var, ":", this.treat), "robust se"]^2 + 2*t*vcov(m)[this.var,paste0(this.var, ":", this.treat)])
  this.results$p.value=coef(summary(m))[paste0(this.var, ":", this.treat), "Pr(>|z|)"]
this.results$model="All"
this.results$term="School Need Index \n Near to Hometown"
ha.results=rbind.fill(ha.results,this.results)




sg=capture.output(stargazer(ha1b.all, ha1b.all.controls, ha1b.c, ha1b.mp, type = "latex", 
          out=paste("./Output/tab_baseline2.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (School Need Index*Distance)",
          order=c("^z_school_need_index:z_school_home_distance$", "^z_school_need_index$", "^z_school_home_distance$"),
         keep=c("^z_school_need_index:z_school_home_distance$", "^z_school_need_index$", "^z_school_home_distance$"),
          covariate.labels = c(labelme("school_need_index:school_home_distance"), labelme("school_need_index"), labelme("z_school_home_distance")),
          no.space=TRUE,
          label=paste("tab_baseline2", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_baseline2_full}).}"), "tab_baseline2.tex", supress_output=F)


sg=capture.output(stargazer(ha1b.all, ha1b.all.controls, ha1b.c, ha1b.mp, type = "latex", 
          out=paste("./Output/tab_baseline2_full.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (School Need Index*Distance) with controls",
          order=c("^z_school_need_index:z_school_home_distance$", "^z_school_need_index$", "^z_school_home_distance$"),
          keep="*",
          #keep=c("^z_school_need_index:z_school_home_distance$", "^z_school_need_index$", "^z_school_home_distance$"),
          covariate.labels = c(labelme("school_need_index:school_home_distance"), labelme("school_need_index"), labelme("z_school_home_distance")),
          no.space=TRUE,
          label=paste("tab_baseline2_full", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}"),"tab_baseline2_full.tex", supress_output=F)


ha2.c = clogit(as.formula(paste("incumbentselected ~ z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_votes==0,])  
this.results=tidy(ha2.c)[1,]
this.results$model="LCs"
this.results$term=labels.all[labels.all$varname=="winner_percent_imp",]$label
ha.results=rbind.fill(ha.results,this.results)

ha2.mp = clogit(as.formula(paste("incumbentselected ~ z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey[mp.survey$information_votes==0,])  
this.results=tidy(ha2.mp)[1,]
this.results$model="MPs"
this.results$term=labels.all[labels.all$varname=="winner_percent_imp",]$label
ha.results=rbind.fill(ha.results,this.results)

ha2.all = clogit(as.formula(paste("incumbentselected ~ z_winner_percent + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_votes==0,])  
this.results=tidy(ha2.all)[1,]
this.results$model="All"
this.results$term=labels.all[labels.all$varname=="winner_percent_imp",]$label
ha.results=rbind.fill(ha.results,this.results)

controls.t=sub("winner_percent_imp \\+", "", controls)
ha2.c.controls = clogit(as.formula(paste("incumbentselected ~ z_winner_percent", controls.t," + strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_votes==0,])  
this.results=tidy(ha2.c.controls)[1,]
this.results$model="LCs with controls"
this.results$term=labels.all[labels.all$varname=="winner_percent_imp",]$label
ha.results=rbind.fill(ha.results,this.results)

ha2.mp.controls = clogit(as.formula(paste("incumbentselected ~ z_winner_percent", controls.t," + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey[mp.survey$information_votes==0,])  
this.results=tidy(ha2.mp.controls)[1,]
this.results$model="MPs with controls"
this.results$term=labels.all[labels.all$varname=="winner_percent_imp",]$label
ha.results=rbind.fill(ha.results,this.results)

ha2.all.controls = clogit(as.formula(paste("incumbentselected ~ z_winner_percent", controls.t," + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys[all.surveys$information_votes==0,])  
this.results=tidy(ha2.all.controls)[1,]
this.results$model="All with controls"
this.results$term=labels.all[labels.all$varname=="winner_percent_imp",]$label
ha.results=rbind.fill(ha.results,this.results)


sg=capture.output(stargazer(ha2.all, ha2.all.controls, ha2.c, ha2.mp, type = "latex", 
          out=paste("./Output/tab_baseline3.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (Incumbent Votes)",
          order=c("^z_winner_percent$"),
          keep=c("^z_winner_percent$"),
          covariate.labels = c(labelme("winner_percent")),
          no.space=TRUE,
          label=paste("tab_baseline3", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_baseline3_full}).}"), "tab_baseline3.tex", supress_output=F)




sg=capture.output(stargazer(ha2.all, ha2.all.controls, ha2.c, ha2.mp, type = "latex", 
          out=paste("./Output/tab_baseline3_full.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (Incumbent Votes) with controls",
          order=c("^z_winner_percent$"),
         # keep=c("^z_winner_percent$"),
          covariate.labels = c(labelme("winner_percent")),
          no.space=TRUE,
          label=paste("tab_baseline3_full", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}"), "tab_baseline3_full.tex", supress_output=F)



controls.t=controls

ha4.c.a = clogit(as.formula(paste("incumbentselected ~ any_children_attend_school + strata(map_id) + cluster(resp_id)")),  method="efron",c.survey)  
this.results=tidy(ha4.c.a)[1,]
this.results$model="LCs"
this.results$term=labels.all[labels.all$varname=="any_children_attend_school",]$label
ha.results=rbind.fill(ha.results,this.results)

ha4.mp.a = clogit(as.formula(paste("incumbentselected ~ any_children_attend_school + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)  
this.results=tidy(ha4.mp.a)[1,]
this.results$model="MPs"
this.results$term=labels.all[labels.all$varname=="any_children_attend_school",]$label
ha.results=rbind.fill(ha.results,this.results)

ha4.all.a = clogit(as.formula(paste("incumbentselected ~ any_children_attend_school + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)  
this.results=tidy(ha4.all.a)[1,]
this.results$model="All"
this.results$term=labels.all[labels.all$varname=="any_children_attend_school",]$label
ha.results=rbind.fill(ha.results,this.results)

controls.t=sub("any_children_attend_school \\+", "", controls)
controls.t=sub("\\+ any_children_attend_school", "", controls)
ha4.c.a.controls = clogit(as.formula(paste("incumbentselected ~ any_children_attend_school", controls.t, " + strata(map_id) + cluster(resp_id)")),  method="efron",c.survey)  
this.results=tidy(ha4.c.a.controls)[1,]
this.results$model="LCs with controls"
this.results$term=labels.all[labels.all$varname=="any_children_attend_school",]$label
ha.results=rbind.fill(ha.results,this.results)

ha4.mp.a.controls = clogit(as.formula(paste("incumbentselected ~ any_children_attend_school", controls.t, " + strata(map_id) + cluster(resp_id)")), method="efron", mp.survey)  
this.results=tidy(ha4.mp.a.controls)[1,]
this.results$model="MPs with controls"
this.results$term=labels.all[labels.all$varname=="any_children_attend_school",]$label
ha.results=rbind.fill(ha.results,this.results)

ha4.all.a.controls = clogit(as.formula(paste("incumbentselected ~ any_children_attend_school", controls.t, " + strata(map_id) + cluster(resp_id)")), method="efron", all.surveys)  
this.results=tidy(ha4.all.a.controls)[1,]
this.results$model="All with controls"
this.results$term=labels.all[labels.all$varname=="any_children_attend_school",]$label
ha.results=rbind.fill(ha.results,this.results)



sg=capture.output(stargazer(ha4.all.a, ha4.all.a.controls, ha4.c.a, ha4.mp.a, type = "latex", 
          out=paste("./Output/tab_baseline4.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (Family Attends School)",
          order=c("^any_children_attend_school$"),
          keep=c("^any_children_attend_school$"),
          covariate.labels = c(labelme("any_children_attend_school")),
          no.space=TRUE,
          label=paste("tab_baseline4", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_baseline4_full}).}"), "tab_baseline4.tex", supress_output=F)


sg=capture.output(stargazer(ha4.all.a, ha4.all.a.controls, ha4.c.a, ha4.mp.a, type = "latex", 
          out=paste("./Output/tab_baseline4_full.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (Family Attends School) with controls",
          order=c("^any_children_attend_school$"),
          #keep=c("^any_children_attend_school$"),
          keep="*",
          covariate.labels = c(labelme("any_children_attend_school")),
          no.space=TRUE,
          label=paste("tab_baseline4_full", sep=""),
          table.placement = "H"
          
))
stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}"), "tab_baseline4_full.tex")

ha6.c = clogit(as.formula(paste("incumbentselected ~ z_past_aid_project + strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_aid==0,])  
this.results=tidy(ha6.c)[1,]
this.results$model="LCs"
this.results$term=labels.all[labels.all$varname=="past_aid_project",]$label
ha.results=rbind.fill(ha.results,this.results)

ha6.mp = clogit(as.formula(paste("incumbentselected ~ z_past_aid_project + strata(map_id) + cluster(resp_id)")),  method="efron", mp.survey[mp.survey$information_aid==0,])  
this.results=tidy(ha6.mp)[1,]
this.results$model="MPs"
this.results$term=labels.all[labels.all$varname=="past_aid_project",]$label
ha.results=rbind.fill(ha.results,this.results)

ha6.all = clogit(as.formula(paste("incumbentselected ~ z_past_aid_project + strata(map_id) + cluster(resp_id)")),  method="efron", all.surveys[all.surveys$information_aid==0,])  
this.results=tidy(ha6.all)[1,]
this.results$model="All"
this.results$term=labels.all[labels.all$varname=="past_aid_project",]$label
ha.results=rbind.fill(ha.results,this.results)

controls.t=sub("\\+ past_aid_project", "", controls)

ha6.c.controls = clogit(as.formula(paste("incumbentselected ~ z_past_aid_project", controls.t, " + strata(map_id) + cluster(resp_id)")), method="efron", c.survey[c.survey$information_aid==0,])  
this.results=tidy(ha6.c.controls)[1,]
this.results$model="LCs with controls"
this.results$term=labels.all[labels.all$varname=="past_aid_project",]$label
ha.results=rbind.fill(ha.results,this.results)

ha6.mp.controls = clogit(as.formula(paste("incumbentselected ~ z_past_aid_project", controls.t, " + strata(map_id) + cluster(resp_id)")),  method="efron", mp.survey[mp.survey$information_aid==0,])  
this.results=tidy(ha6.mp.controls)[1,]
this.results$model="MPs with controls"
this.results$term=labels.all[labels.all$varname=="past_aid_project",]$label
ha.results=rbind.fill(ha.results,this.results)

ha6.all.controls = clogit(as.formula(paste("incumbentselected ~ z_past_aid_project", controls.t, " + strata(map_id) + cluster(resp_id)")),  method="efron", all.surveys[all.surveys$information_aid==0,])  
this.results=tidy(ha6.all.controls)[1,]
this.results$model="All with controls"
this.results$term=labels.all[labels.all$varname=="past_aid_project",]$label
ha.results=rbind.fill(ha.results,this.results)



sg=capture.output(stargazer(ha6.all, ha6.all.controls, ha6.c, ha6.mp, type = "latex", 
          out=paste("./Output/tab_baseline5.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (Aid Project Count)",
          order=c("^z_past_aid_project$"),
          keep=c("^z_past_aid_project$"),
          covariate.labels = c(labelme("past_aid_project")),
          omit="*",
          no.space=TRUE,
          label=paste("tab_baseline5", sep=""),
          table.placement = "H"
          
))
stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_baseline5_full}).}"), "tab_baseline5.tex", supress_output=F)


sg=capture.output(stargazer(ha6.all, ha6.all.controls, ha6.c, ha6.mp, type = "latex", 
          out=paste("./Output/tab_baseline5_full.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (Aid Project Count) with controls",
          order=c("^z_past_aid_project$"),
          #keep=c("^z_past_aid_project$"),
          keep="*",
          covariate.labels = c(labelme("past_aid_project")),
          #omit="*",
          no.space=TRUE,
          label=paste("tab_baseline5_full", sep=""),
          table.placement = "H"
          
))
stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}"), "tab_baseline5_full.tex")


controls.t=controls
ha7.c.controls = clogit(as.formula(paste("incumbentselected ~ z_pop_per_hectacre", controls.t, " + strata(map_id) + cluster(resp_id)")),  method="efron", c.survey)
this.results=tidy(ha7.c.controls)[1,]
this.results$model="LCs with controls"
this.results$term=labels.all[labels.all$varname=="pop_per_hectacre",]$label
ha.results=rbind.fill(ha.results,this.results)

ha7.mp.controls = clogit(as.formula(paste("incumbentselected ~ z_pop_per_hectacre", controls.t, " + strata(map_id) + cluster(resp_id)")),  method="efron", mp.survey)
this.results=tidy(ha7.mp.controls)[1,]
this.results$model="MPs with controls"
this.results$term=labels.all[labels.all$varname=="pop_per_hectacre",]$label
ha.results=rbind.fill(ha.results,this.results)

ha7.all.controls = clogit(as.formula(paste("incumbentselected ~ z_pop_per_hectacre", controls.t, " + strata(map_id) + cluster(resp_id)")),  method="efron", all.surveys)
this.results=tidy(ha7.all.controls)[1,]
this.results$model="All with controls"
this.results$term=labels.all[labels.all$varname=="pop_per_hectacre",]$label
ha.results=rbind.fill(ha.results,this.results)


ha7.c = clogit(as.formula(paste("incumbentselected ~ z_pop_per_hectacre + strata(map_id) + cluster(resp_id)")),  method="efron", c.survey)
this.results=tidy(ha7.c)[1,]
this.results$model="LCs"
this.results$term=labels.all[labels.all$varname=="pop_per_hectacre",]$label
ha.results=rbind.fill(ha.results,this.results)

ha7.mp = clogit(as.formula(paste("incumbentselected ~ z_pop_per_hectacre + strata(map_id) + cluster(resp_id)")),  method="efron", mp.survey)
this.results=tidy(ha7.mp)[1,]
this.results$model="MPs"
this.results$term=labels.all[labels.all$varname=="pop_per_hectacre",]$label
ha.results=rbind.fill(ha.results,this.results)

ha7.all = clogit(as.formula(paste("incumbentselected ~ z_pop_per_hectacre + strata(map_id) + cluster(resp_id)")),  method="efron", all.surveys)
this.results=tidy(ha7.all)[1,]
this.results$model="All"
this.results$term=labels.all[labels.all$varname=="pop_per_hectacre",]$label
ha.results=rbind.fill(ha.results,this.results)



sg=capture.output(stargazer(ha7.all, ha7.all.controls, ha7.c, ha7.mp, type = "latex", 
          out=paste("./Output/tab_baseline6.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (Population Density)",
          order=c("^z_pop_per_hectacre$"),
          keep=c("^z_pop_per_hectacre$"),
          covariate.labels = c(labelme("pop_per_hectacre")),
          no.space=TRUE,
          label=paste("tab_baseline6", sep=""),
          table.placement = "H"
          
))

stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_baseline6_full}).}"), "tab_baseline6.tex", supress_output=F)


sg=capture.output(stargazer(ha7.all, ha7.all.controls, ha7.c, ha7.mp, type = "latex", 
          out=paste("./Output/tab_baseline6_full.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (Population Density) with controls",
          order=c("^z_pop_per_hectacre$"),
         # keep=c("^z_pop_per_hectacre$"),
         keep="*",
          covariate.labels = c(labelme("pop_per_hectacre")),
          no.space=TRUE,
          label=paste("tab_baseline6_full", sep=""),
          table.placement = "H"
          
))


stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}"), "tab_baseline6_full.tex")


controls.t=controls
ha8.c.controls = clogit(as.formula(paste("incumbentselected ~ z_school_home_distance", controls.t, " + strata(map_id) + cluster(resp_id)")),  method="efron", c.survey)  
this.results=tidy(ha8.c.controls)[1,]
this.results$model="LCs with controls"
this.results$term=labels.all[labels.all$varname=="school_home_distance",]$label
ha.results=rbind.fill(ha.results,this.results)

ha8.mp.controls = clogit(as.formula(paste("incumbentselected ~ z_school_home_distance", controls.t, " + strata(map_id) + cluster(resp_id)")),  method="efron", mp.survey)  
this.results=tidy(ha8.mp.controls)[1,]
this.results$model="MPs with controls"
this.results$term=labels.all[labels.all$varname=="school_home_distance",]$label
ha.results=rbind.fill(ha.results,this.results)

ha8.all.controls = clogit(as.formula(paste("incumbentselected ~ z_school_home_distance", controls.t, " + strata(map_id) + cluster(resp_id)")),  method="efron", all.surveys)  
this.results=tidy(ha8.all.controls)[1,]
this.results$model="All with controls"
this.results$term=labels.all[labels.all$varname=="school_home_distance",]$label
ha.results=rbind.fill(ha.results,this.results)



ha8.c = clogit(as.formula(paste("incumbentselected ~ z_school_home_distance + strata(map_id) + cluster(resp_id)")),  method="efron", c.survey)  
this.results=tidy(ha8.c)[1,]
this.results$model="LCs"
this.results$term=labels.all[labels.all$varname=="school_home_distance",]$label
ha.results=rbind.fill(ha.results,this.results)

ha8.mp = clogit(as.formula(paste("incumbentselected ~ z_school_home_distance + strata(map_id) + cluster(resp_id)")),  method="efron", mp.survey)  
this.results=tidy(ha8.mp)[1,]
this.results$model="MPs"
this.results$term=labels.all[labels.all$varname=="school_home_distance",]$label
ha.results=rbind.fill(ha.results,this.results)

ha8.all = clogit(as.formula(paste("incumbentselected ~ z_school_home_distance + strata(map_id) + cluster(resp_id)")),  method="efron", all.surveys)  
this.results=tidy(ha8.all)[1,]
this.results$model="All"
this.results$term=labels.all[labels.all$varname=="school_home_distance",]$label
ha.results=rbind.fill(ha.results,this.results)


sg=capture.output(stargazer(ha8.all, ha8.all.controls, ha8.c, ha8.mp, type = "latex", 
          out=paste("./Output/tab_baseline7.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (Distance)",
          order=c("^z_school_home_distance$"),
          keep=c("^z_school_home_distance$"),
          covariate.labels = c(labelme("school_home_distance")),
          no.space=TRUE,
          label=paste("tab_baseline7", sep=""),
          table.placement = "H"
          
))
stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician. Full model results can be found on the APSR dataverse 'Replication Notes and Output.pdf' file at \\url{", dataverse_markdown_url,"} (Table \\ref{tab_baseline7_full}).}"), "tab_baseline7.tex", supress_output=F)


sg=capture.output(stargazer(ha8.all, ha8.all.controls, ha8.c, ha8.mp, type = "latex", 
          out=paste("./Output/tab_baseline7_full.tex", sep=""), 
          column.labels = c("All Surveys","with Controls", "Councillors", "MPs"),
          model.names=FALSE, header=FALSE, keep.stat = c("n","f", "rsq"), dep.var.labels.include=FALSE,
          notes = "replace me",
          dep.var.caption  = "",
          title="Estimates from Figure 7 (Distance) with controls",
          order=c("^z_school_home_distance$"),
          #keep=c("^z_school_home_distance$"),
          keep="*",
          covariate.labels = c(labelme("school_home_distance")),
          no.space=TRUE,
          label=paste("tab_baseline7_full", sep=""),
          table.placement = "H"
          
))
stargazer_print(sg, paste0("\\multicolumn{5}{p{\\textwidth}}{This table shows the coefficients (in log odds) from conditional logit regressions on school selection. Standard errors are clustered on politician.}"), "tab_baseline7.tex")




ha.results$exp_estimate = exp(ha.results$estimate)
ha.results=ha.results[!is.na(ha.results$model),]
ha.results=ha.results[order(ha.results$model, ha.results$model),]
ha.results$conf.low=exp(ha.results$estimate + ha.results$robust.se*qt(0.025, df=ha1.all$n-1))
ha.results$conf.high=exp(ha.results$estimate + ha.results$robust.se*qt(0.975, df=ha1.all$n-1))
ha.results$estimate=exp(ha.results$estimate)



ha.results$shape=2
library(wesanderson)

ha.results=ha.results[ha.results$model %in% c("All", "MPs", "LCs"),]


unplot=dwplot(ha.results[!is.na(ha.results$estimate),],dot_args = list(aes(shape = as.character(ha.results$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+  theme_bw() + xlab("Marginal Effect \n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
        legend.position = c(0.75, 0.01),
        legend.justification = c(0, 0), 
        legend.background = element_rect(colour="black", size=0.2),
        legend.margin=margin(l = 0.03, r=0.1, t=0,b=0.03, unit='cm'),
        legend.title = element_blank()) +
        coord_cartesian(xlim=c(0.5, 2.2))+
  scale_color_manual(values=wes_palette(n=4, name="Moonrise2"))+
        guides(colour = guide_legend(override.aes=list(shape=c(15,17,16))), shape="none") #changes shape of points in legend

pdf("./Output/baseline_plot_mp_lc.pdf",width=5, height=3.5)
unplot
dev.off()
unplot

ha.results=ha.results[ha.results$model %in% c("All"),]

unplot=dwplot(ha.results[!is.na(ha.results$estimate),],dot_args = list(aes(shape = as.character(ha.results$model))),
       vline = geom_vline(xintercept = 1, colour = "black", linetype = 2, size=0.4)
)+  theme_bw() + xlab("Marginal Effect \n(Change in Odds of School Selection)") + ylab("") +
  theme(plot.title = element_text(face="bold"),
           legend.position = "none") +
        coord_cartesian(xlim=c(0.5, 2.2))+
  scale_color_manual(values=wes_palette(n=2, name="Moonrise2")[2])

pdf("./Output/baseline_plot.pdf",width=5, height=3.2)
unplot
dev.off()
unplot


```
